How can you “read” into variables using IFS and a variable?
I am trying to loop over some data paired by a pipe to be split and worked on. The error I am getting is read: 'site|database': not a valid identifier
SITES="abc|abc xyz|asdf"
for site in $SITES;
do
IFS="|" read domain database <<< echo $site; # es no bueno mi amigo
echo "Site: $domain \t\t\t Database: $database";
done;
Am I just doing this the hard way? I am not a native Basher. 😉
The problem with your script is that you are not passing the Here String to
readcorrectly. It should be done like this:Remember to quote the variable as well.
Your script will then work.
Here is the fixed script:
It prints: