Hey guys! A few weeks ago I wrote an article called All About Bash Redirections. It explains all the possible bash redirections with illustrations. I thought it would be a great idea to make a cheat sheet that summarizes all these redirections. So I did.

As you can see, not only error messages have been printed to the console, but ls also returned an error (2). This could be essential for scripts and I personally would recommend redirection to /dev/null.

Just to note that the Here String ("<<<") is not just for text strings, but is subject to normal Bash word expansion. This means you can do things like cat <<< "$(/usr/bin/date)".

I use this construction nearly every day. A common use case for me is with the at command, which doesn't accept command line input for some silly reason. I work around it by doing: at 5pm <<< "$(gxmessage 'Take steak out of freezer')".

Of those, only PIPESTATUS and |& are actually bash-only. The title of the cheatsheet contains "Bash". Anybody who assumes that means POSIX deserves to have things broken, as do users of horrible pointless shells such as Dash.

For various reasons, |& should probably be discouraged even in Bash scripts.