O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5.9. Merging standard output and standard error

When merging output and errors, the shell evaluates the command from left to right, which is really all you need to know when putting mergers together. Here’s an example.

						$ cleanup >cleanup.out 2>&1
					

In the above example the script cleanup directs all output (>) to a file called cleanup.out, and all errors (2), are directed to (>) the same place as the output (&1), which is cleanup.out.

						$ grep "standard" * > grep.out 2>&1
					

In the above example all output from the grep command is put into the output file grep.out. When you use here documents, you will probably need to capture all the output to a file in case errors are encountered. To do this you need to use 2>&1 as part of the command. Here’s ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required