3.4 Redirecting STDOUT to STDIN: “|”
Often it is handy to redirect the STDOUT of one command to the STDIN of another command. This can be done using the pipe operator |.
ls | head -n2
#ls.all
#ls.err
ls | head -n2 | sed ’s/ls/blah/’
#blah.all
#blah.err
head -n2 < ls.txt | sed ’s/l/L/’
#Ls.aLL
#Ls.err
echo "5 + 21 * 30" | bc
#635We redirect the STDOUT of “ls” to the STDIN of “head” and so on. Basically, we pass the output of one command as the input for the next command and we can do it as long as the STDIN is valid.