Print output of cat statement in bash script loop

Viewed 55163

I'm trying to execute a command for each line coming from a cat command. I'm basing this on sample code I got from a vendor.

Here's the script:

for tbl in 'cat /tmp/tables'
do
   echo $tbl
done

So I was expecting the output to be each line in the file. Instead I'm getting this:

cat
/tmp/tables

That's obviously not what I wanted.

I'm going to replace the echo with an actual command that interfaces with a database.

Any help in straightening this out would be greatly appreciated.

5 Answers

You can do a lot of parsing in bash by redefining the IFS (Input Field Seperator), for example

IFS="\t\n"  # You must use double quotes for escape sequences. 
for tbl in `cat /tmp/tables` 
do 
    echo "$tbl"
done
Related