I’m not a Bash expert, but I’ve followed Copilot examples, and the following should work, but it doesn’t:
# CSV file contents
lineNo, column1, column2, column3, column4
1, true, true, true, abc
2, true, false, true , 123
3, false, true, false, xyz
0
Bash script:
while IFS=, read -r lineNo column1 column2 column3 column4
do
echo $column4
if [ "$column4" = "123" ]; then
echo "condition is true"
else
echo "condition is false"
fi
done < <(tail -n +2 $setupFileLocation)
However, my results are as follows:
abc
condition is false
123
condition is false
xyz
condition is false
Why are the actual variable values being ignored? They are correct in the echo
, but the IF…THEN isn’t acknowledging the changing value. I’ve tested this with making the lineNo #1 the tested value, and it doens’t make a difference. All conditions return “false”.
Why the trailing zero? If it isn’t there the read
Bash command only returns the header and first two rows. I haven’t figured this out yet, but it’s a different subject.
Are there any wonderful Bash SMEs out there who can assist?