I have a csv file that i am reading with a "while read" statement and i want to run an if statement on one of the fields in the csv.
====================================
csv file
client1,admin,password,5.9
client2,admin,password,5.8
====================================
this is my script
while read clientid user pass version
do
if [ '$version' = "5.9" ];
then
echo "IS"
else
echo "NOT"
fi
done < $1
The problem is that the if statement does not work.
It does not echo IS when the version is 5.9, it just keeps saying NOT, unless i change it to !=
I have tried using single and double quotes, even without... still doesn't work as expected.
The goal is to run commands until the end of the file. Is this script correct for doing this?
Obviously the IS and NOT would be replaced by actual command, this is just for testing.
read
will not split on commas by default. You need to tell it to do that. Print out the value of$clientid
,$user
,$pass
, and$version
in your loop to see what you get. – Etan Reisner Jul 23 '14 at 21:46$IFS
— the Internal Field Separator. This is used byread
(and many other programs) to separate text strings. – baum Jul 23 '14 at 21:51IFS=,
orread -d,
? I'm getting really weird output when using this. – Costi Ciudatu Jul 23 '14 at 22:37