0

I am studying for my RHCSA and already have my Linux+ and I'm trying to better understand shell redirection beyond just understanding the basic use cases and I am trying to grasp it at a deeper conceptual level.

The information that I'm referencing is from https://www.redhat.com/sysadmin/linux-shell-redirection-pipelining.

Couple of questions..

The doc mentions:

  1. command 2>&1: Sends error output to standard output
  2. command > file 2>&1: Sends standard output and the error output to a file

Am I understanding this correctly in the below interpretation?

Basically how I read this is that in line #1 it is redirecting STD-ERR to STD-OUT data stream and then printing STD-OUT to the screen? And in line #2 it is processing the latter (2>&1) argument before the former (> file) argument meaning that it doesn't process arguments from left to right but instead in some sort of weird Linux PEMDAS? So if I'm understanding this correctly, the 2nd argument is processed and then the first argument? otherwise the "file" would not contain STD-ERR and would only contain STD-OUT.

I just want to ensure that I am grasping this correctly?

Thomas Dickey
  • 76,765
Kyle
  • 9
  • 2
  • No, you're not. > file means to make stdout point to the file, 2>&1 means to make stderr point to where ever stdout points to now. The latter is more like making a copy of the stdout file descriptor to the stderr file descriptor. – ilkkachu May 20 '22 at 22:23
  • The example into the reference manual is good, ls > dirlist 2>&1 vs ls 2>&1 > dirlist. (1) Evaluation is from left to right and (2) Order matters. – thanasisp May 20 '22 at 22:23

0 Answers0