redirection 

Send to Kindle
home » snippets » zsh » redirection



Snippets

Replacing cat

The substitution ‘$(cat foo)’ may be replaced by the equivalent but faster ‘$(<foo)’

Redirection into a while loop

From stackexchange: Parsing a file

Redirection into a while loop allows additional commands to be made and variables to be set:

while read -r dir; do mkdir $dir; done < myfile

An example of a more complicated structure would be:

now=`date +%Y%m%d.%H%M%S`
while read -r dir; do
    newdistfile="/tmp/dist-`echo $dir | tr / _`.tgz"
    mv $dir ~/backups/$dir.$now &&
        mkdir $dir &&
        tar xzfC $newdistfile $dir
done < myfile

This is not something that xargs could do without writing a 'helper program'.