Bash Foreach Loop
Answer :
Something like this would do:
xargs cat <filenames.txt The xargs program reads its standard input, and for each line of input runs the cat program with the input lines as argument(s).
If you really want to do this in a loop, you can:
for fn in `cat filenames.txt`; do echo "the next file is $fn" cat $fn done "foreach" is not the name for bash. It is simply "for". You can do things in one line only like:
for fn in `cat filenames.txt`; do cat "$fn"; done Reference: http://www.cyberciti.biz/faq/linux-unix-bash-for-loop-one-line-command/
Here is a while loop:
while read filename do echo "Printing: $filename" cat "$filename" done < filenames.txt
Comments
Post a Comment