Redirecting stderr to stdout in Bash 4

It's common when writing shell scripts or running cronjobs to want to merge standout error (file descriptor 2) with standard output (file descriptor 1) and write it to a file or /dev/null. The traditional way in shell scripts to redirect stderr to stdout looks like this:

$ somecommand > /dev/null 2>&1

However, Bash 4 introduced an additional, simpler syntax for accomplishing this and it's slightly easier to remember.

$ somecommand &> /dev/null

Of course, the older syntax is still valid in Bash 4 and will likely always be supported.

Posted in on
Tagged with bash commandline