LFCS Exam QuestionsBrowse all questions from this exam

LFCS Exam - Question 40


In Bash, inserting 1>&2 after a command redirects

Show Answer
Correct Answer: C

In Bash, '1>&2' redirects standard output (file descriptor 1) to standard error (file descriptor 2). This means that the output that would typically go to standard output will be sent to standard error instead.

Discussion

2 comments
Sign in to comment
BuruguduystunstugudunstuyOption: C
Jan 3, 2023

In Bash, inserting '1>&2' after a command redirects standard output to standard error. Option C is the correct answer. In Bash, the '>' symbol is used to redirect output from a command to a file. The '&' symbol is used to specify a file descriptor, which is a numerical identifier for a file that is used by the operating system to keep track of open files. The number '1' specifies the standard output file descriptor, and the number '2' specifies the standard error file descriptor. Therefore, the command '1>&2' redirects the standard output file descriptor ('1') to the standard error file descriptor ('2'). This means that the output of the command will be written to the standard error instead of the standard output.

Buruguduystunstugudunstuy
Jan 3, 2023

The other options do not accurately describe what happens when '1>&2' is inserted after a command: Option A: Standard error is not redirected to standard input. Option B: Standard input is not redirected to standard error. Option D: Standard error is not redirected to standard output. Option E: Standard output is not redirected to standard input. To redirect standard error to standard output, you can use the command '2>&1'. This will redirect the standard error file descriptor ('2') to the standard output file descriptor ('1'). This means that the error output of the command will be written to the standard output along with the normal output.

7MesserOption: C
Mar 26, 2024

This is wrong. It means standard output to standard error, what is already unusual. https://www.thomas-krenn.com/de/wiki/Bash_stdout_und_stderr_umleiten