What is the effect of using >&2 in a command?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

What is the effect of using >&2 in a command?

Explanation:
Redirecting with >&2 makes the command’s standard output go to the same place as standard error. In Bash, stdout is FD 1 and stderr is FD 2; appending >&2 duplicates FD 2 onto FD 1, so anything that would be printed to stdout is now sent to the error stream. This changes where the normal output goes, but it does not change the command’s exit status, nor does it send output to /dev/null (that would require a different redirection, like > /dev/null 2>&1). For example, echo hi >&2 writes to the error stream instead of normal output.

Redirecting with >&2 makes the command’s standard output go to the same place as standard error. In Bash, stdout is FD 1 and stderr is FD 2; appending >&2 duplicates FD 2 onto FD 1, so anything that would be printed to stdout is now sent to the error stream. This changes where the normal output goes, but it does not change the command’s exit status, nor does it send output to /dev/null (that would require a different redirection, like > /dev/null 2>&1). For example, echo hi >&2 writes to the error stream instead of normal output.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy