Changes

Jump to: navigation, search

BASH Redirection

760 bytes added, 22:30, 15 September 2008
no edit summary
&>''filename''
 
= Using Pipes =
 
A pipe is a buffered mechanism for connecting the output of one command to the input of another. The symbol used is <code>|</code>:
 
cal | lpr
 
This prints the current calendar on the (default) printer.
 
Multiple pipes may be used together in a long pipeline:
 
grep "/bin/bash$" /etc/passwd | cut -d: -f1 | sort | mail -s "Bash users" joe@example.com
 
This pipeline selects all BASH users from the system account file /etc/passwd, cuts out the user name, sorts them into order, and e-mails them to joe@example.com with the subject line "Bash users".
 
You can use the <code>2>&1</code> syntax with pipes:
 
ls /dev/snd/* /dev/asrf2as/423asfd 2>&1 | lpr
 
Both the stdout and stderr of the <code>ls</code> command will be sent to the printer.

Navigation menu