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.
- Readers' Choice Awards 2013
- Mars Needs Women
- Sublime Text: One Editor to Rule Them All?
- RSS Feeds
- Raspberry Pi: the Perfect Home Server
- December 2013 Issue of Linux Journal: Readers' Choice
- Linux Kernel News - November 2013
- IBM Will Minimize Impact of Future Disasters
- Tech Tip: Really Simple HTTP Server with Python
- Linux Systems Administrator
1 hour 12 min ago
- This should be very helpful
2 hours 26 min ago
- As much as I share your point
4 hours 46 min ago
- So girls had it better ?
8 hours 18 min ago
- Reply to comment | Linux Journal
8 hours 38 min ago
- why is GNOME 3 in the fifth position at 14.1 %?
14 hours 10 min ago
- Sublime Is Brilliant!
19 hours 13 min ago
19 hours 32 min ago
- Rapid[Disk,Cache] better than native ram caching?
19 hours 57 min ago
- Nothing is perfect
20 hours 10 min ago