Search code examples
bashshellunixconsoleexit-code

Suppress stderr console output but keep exit code in Shell


is there a way how I can suppress the console output of sdterr but keep the exit code?

I did

#!/bin/sh
command 2> /dev/null
STATUS=$?

but that way, even the exit code is suppressed (and turns into 0).

I want to achieve that I can get when a command fails without clustering the console unless a --verbose flag is enabled but it should quit the program when a command fails.


Solution

  • Nevermind, this actually works and I had a mistake elsewhere in my script.

    Today I also learned that assigning a variable also counts as a "command" and thus the exit code remained 0