Redirect both stdout and stderr to dev null using > /dev/null 2>&1 for linux commands and scripts

/tmp()$ cat out_err_redirect_test.sh 
echo message to stdout
echo message to stderr >&2

/tmp()$ bash out_err_redirect_test.sh 
message to stdout
message to stderr

# Message to stdout is redirected to dev null
/tmp()$ bash out_err_redirect_test.sh  > /dev/null
message to stderr

# Message to stderr is redirected to dev null
/tmp()$ bash out_err_redirect_test.sh  2>/dev/null
message to stdout

# Message to stderr and stdout is redirected to dev null
/tmp()$ bash out_err_redirect_test.sh  > /dev/null 2>/dev/null

# Messaged to stdout is redirected to dev null, and stderr to configured stdout (implies dev null)
/tmp()$ bash out_err_redirect_test.sh  > /dev/null 2>&1

# Message to stderr is redirected to stdout (screen) and stdout to dev null
/tmp()$ bash out_err_redirect_test.sh 2>&1 > /dev/null 
message to stderr

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Avoid using global/class-level mutable datatypes like list/dicts

Weakref proxy is for instance only ...