[~]$ kill %123

bash: kill: %123: no such job

[~]$ kill %123 2>&1 > /dev/null

bash: kill: %123: no such job

I want to disable all output during killing background jobs.

The first output is expected. However, the second output is not.

As showed in the command line, I add 2>&1 to redirect stderr to stdout, and use > /dev/null to redirect all output to null device. But the output is still showed on the terminal.

Any explanations?

Thanks in advance.

Updated Information:

The following command works as expected:

kill %123 > /dev/null 2>&1

The output redirection is a property of the process. Therefor when redirecting with 2>&1 this sets the current output of stdout to stderr which is the current TTY then the following > sets the stdout to /dev/null which leaves stderr set to the TTY. In your updated information you've correctly set the stdout first so both end up being /dev/null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.