Changes

Jump to: navigation, search

BASH Redirection

185 bytes added, 10:11, 21 September 2008
Standard File Descriptors
|}
When running commands from the command line, all three of these file descriptors is are connected to the terminal, so the input to process comes from the terminal (keyboard), and normal output as well as error output goes to the terminal (screen).
The meaning of these file descriptors may vary in some contexts; for example, when a program is executed as a CGI script by a webserver, the CGI standard dictates that stdin receives POSTed data from the browser, and stdout is used to send the resulting data (typically HTML) from the script. Stderr is usually sent to a logfile.
cal 16 2009 >output 2>error
This command will fail because there is no 16th month in the year 2009 (or any year!). The stdout is redirected to the file "output", but there will be no output. The stderr (error message) will be redirected to the file "calendar.txterror".
== Redirecting Input ==
Both the stdout and stderr of the <code>ls</code> command will be sent to the printer.
= Using stdout as an Argument = The <code>$( )</code> can be used to capture stdout of a command and use it as an argument to another command:  vi $(date +%Y)-notes.txt  [[Category:BASH]][[Category:Linux]]

Navigation menu