Bash Input Redirection

The 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
> EOF

A "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' >&2

This 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.

Trending Topics

Webinar: 8 Signs You’re Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
11am CDT, April 29th

Join Linux Journal and Pat Cameron, Director of Automation Technology at HelpSystems, as they discuss the eight primary advantages of moving beyond cron job scheduling. In this webinar, you’ll learn about integrating cron with an enterprise scheduler.