Run a command on each line of a text file

view full story

http://www.unix.com – Say I have a text file, with several lines. Each line may contain spaces or the # symbol. For each line, I want to pass that line as the path of a file, in order to add it to a tar file. I've tried this but doesn't work: Code: cat contents.txt | xargs -0 `tar -uvf contents.tar $1` Any ideas? Note: I've tried tar with -T option but would like to do it another way. I've tried as well this but separates lines containing spaces: Code: for i in $(cat file)  do  #do your stuff to $i here  done (HowTos)