ln linux, when you issue command: ls existing_file.txt non-existing_file.txt > output.txt 2>&1
Why does it matter what order you place the "> output.txt" part vs the "2>&1" part in (i.e. why can't you reverse the order of these parts)?
Answer
Because the order of redirection execution is done right to left.
In other words, 2>&1 is done first. i.e. send stderr to stdout, then send stdout, 1> or just >, (which now combines stderr) to output.txt. Putting them in reverse would send stdout to output.txt (without combining it with stderr) then just combine stderr with stdout (which would just be seen in the prompt only)
Question
ln linux, when you issue command: ls existing_file.txt non-existing_file.txt > output.txt 2>&1
Why does it matter what order you place the "> output.txt" part vs the "2>&1" part in (i.e. why can't you reverse the order of these parts)?
Answer
?
Question
ln linux, when you issue command: ls existing_file.txt non-existing_file.txt > output.txt 2>&1
Why does it matter what order you place the "> output.txt" part vs the "2>&1" part in (i.e. why can't you reverse the order of these parts)?
Answer
Because the order of redirection execution is done right to left.
In other words, 2>&1 is done first. i.e. send stderr to stdout, then send stdout, 1> or just >, (which now combines stderr) to output.txt. Putting them in reverse would send stdout to output.txt (without combining it with stderr) then just combine stderr with stdout (which would just be seen in the prompt only)
If you want to change selection, open document below and click on "Move attachment"
8. Streams and sed -- The Stream Editor 1>A 2>&1 cat A Now A contains both the error message and the normal output. The >& is called a redirection operator. x >& y tells the shell to write pipe x into pipe y. <span>Redirection is specified from right to left on the command-line. Hence, the above command means to mix stderr into stdout and then to redirect stdout to the file A . Finally, ls existing_file non-existing_file 2>A 1>&2
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.