Content deleted Content added
Clean up duplicate template arguments using findargdups |
|||
Line 89:
Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge [[Standard streams#Standard error (stderr)|standard error]] into [[Standard streams#Standard output (stdout)|standard output]] so error messages can be processed together with (or alternately to) the usual output. For example, {{code|lang=bash|1=find / -name .profile > results 2>&1}} will try to find all files named {{mono|.profile}}. Executed without redirection, it will output hits to [[stdout]] and errors (e.g. for lack of privilege to traverse protected directories) to [[stderr]]. If standard output is directed to file {{mono|results}}, error messages appear on the console. To see both hits and error messages in file {{mono|results}}, merge [[stderr]] (handle 2) into [[stdout]] (handle 1) using {{code|2>&1}}.
If the merged output is to be piped into another program, the file merge sequence {{code|2>&1}} must precede the pipe symbol, thus, {{code|lang=bash|1=find / -name .profile 2>&1
A simplified but non-POSIX conforming form of the command, {{code|lang=bash|1=command > file 2>&1}} is (not available in Bourne Shell prior to version 4, final release, or in the standard shell [[Debian Almquist shell]] used in Debian/Ubuntu): {{code|lang=bash|1=command &>file}} or {{code|lang=bash|1=command >&file}}.
|