I’m trying to read MySQL results via a loop. I have this working but I have a small issue.
The code I’m using is
while IFS=$'t' read fieldA fieldB fieldC fieldD; do
echo "$fieldA $fieldB $fieldC $fieldD"
done < <(mysql -N -u $mysql --password=$pass database -h $host -e "SELECT BLAB BLABBLAB BLABBLAB BLAB")
If one of the fields is empty then the variable is populated with the value from the next field.
eg:
if fieldC is empty echo $feildC
will show the results from fieldD
if fieldB and fieldC are empty echo $feildB
will show the results from fieldD
How do I account for the empty fields ? I was hoping the variable would return null or blank.
Thanks