linux - order of 2>&1 when redirecting std error to file -


i'm seeing different formats redirecting std output file :

a.  command 1&2>output.txt b.  command >output.txt 2>&1 c.  command 2>&1>output.txt   d.  command &>output.txt 

is there difference between these? if 2>&1 placed @ end (b) , how redirect stderr of first command ?

yes. order matters. > may bring idea of pointing , pointers/references , word "redirect", fd redirections more assignments. is, if

exec 2>&1 1>output.txt

it "assign" current "value" (the actual file opened file descriptor) of file descriptor 1 file descriptor 2 , open output.txt , assign file descriptor 1.

what won't point &2 (read & "file descriptor") &1. won't make accessing &2 query &1. file descriptor ever associated actual file, never file descriptor. 2>&1 associates file opened under &1 &2. doesn't redirect &2 &1 in sense writing &2 make write &1 associated @ moment. &1 can later reopened different file associated @ time of 2>&1 redirection, won't affect &2 writes to.

check out dup2(2) if want know how functionality exposed @ system call level.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -