Shell script for loop is behaving unexpected ! The requirement is need to iterate the loop line by line of the property file. Its mandatory to use the for loop.
hostnamefl=/tmp/propperty.txt
for property in $(cat $hostnamefl)
do
hostname=`echo $property | awk '{print $1}'`
echo $hostname
user=`echo $property | awk '{print $2}'`
echo $user
pas=`echo $property | awk '{print $3}'`
echo $pas
echo "---------------------------------------------------------------------------------"
done
propperty.txt
host1 host1user host1pas
host2 host2user host2pas
host3 host3user host3pas
I am getting the result as given below :
host1
---------------------------------------------------------------------------------
host1user
---------------------------------------------------------------------------------
host1pas
---------------------------------------------------------------------------------
host2
---------------------------------------------------------------------------------
host2user
---------------------------------------------------------------------------------
host2pas
---------------------------------------------------------------------------------
host3
---------------------------------------------------------------------------------
host3user
---------------------------------------------------------------------------------
host3pas
---------------------------------------------------------------------------------
Expected result:
host1
host1user
host1pas
---------------------------------------------------------------------------------
host2
host2user
host2pas
---------------------------------------------------------------------------------
host3
host3user
host3pas
---------------------------------------------------------------------------------
For loop is iterating word by word rather than line by line, how should I resolve it ?