Bash Input Redirection
If you use the shell you surely know about redirection:
# echo 'hello world' >output # cat <outputThe first line writes "hello world" to the file "output", the second reads it back and writes it to standard output (normally the terminal).
Then there are "here" documents:
# cat <<EOF > hello > world > EOFA "here" document is essentially a temporary, nameless file that is used as input to a command, here the "cat" command.
A less commonly seen form of here document is the "here" string:
# cat <<<'hello world'In this form the string following the "<<<" becomes the content of the "here" document.
Another less commonly seen form of redirection is redirecting to a specific file descriptor:
# echo 'Error: oops' >&2This redirects the output of the "echo" command to file descriptor 2, aka standard error. This is useful if you want to keep the error output of your scripts from contaminating the normal output when the output of your script is redirected.
These features work in bash and may not be available in other shells.
Mitch Frazier is an Associate Editor for Linux Journal.
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
|CodeLathe's Tonido Personal Cloud||Apr 19, 2017|
|Wrapping Up the Mars Lander||Apr 18, 2017|
|MultiTaction's MT Canvus-Connect||Apr 17, 2017|
|Android Candy: Facebook Everything?!?!||Apr 14, 2017|
- Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- The Weather Outside Is Frightful (Or Is It?)
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- Bash Shell Script: Building a Better March Madness Bracket
- A Switch for Your RPi
- IGEL Universal Desktop Converter