Shell Script: Echo to Stderr

To distinguish between normal output messages and error messages, sometimes there is a need to write messages to the stderr stream from a shell script. By default, output messages are written to stdout stream only.

To write or echo to stderr, I normally use a custom function that redirects the output of the echo command to the standard error stream.

The above script has a custom function called echo_stderr that performs the stderr redirect.

Let’s name the above script as stderr.sh. Based on the script, if you want to filter out stderr messages, perform a redirect like this.

To filter out stdout messages, perform a similar redirection, but this time by redirecting the stdout stream to the null device.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }