bash - Shell redirection i/o order -
i'm playing i/o shell redirection. commands i've tried (in bash):
ls -al *.xyz 2>&1 1> files.lst
and
ls -al *.xyz 1> files.lst 2>&1
there no *.xyz
file in current folder.
these commands gives me different results. first command shows error message ls: *.xyz: no such file or directory
on screen. second 1 prints error message file. why did first command failed write err output file?
this error:
ls: *.xyz: no such file or directory
is being written on stderr
ls
binary.
however in command:
ls -al *.xyz 2>&1 1> files.lst
you're first redirecting stderr
stdout
default goes tty
(terminal)
and you're redirecting stdout
file files.lst
, remember stderr doesn't redirected file since have stderr
stdout
redirection before stdout
file
redirection. stderr
still gets written tty
in case.
however in 2nd case change order of redirections (first stdout
file
, stderr
stdout
) , rightly redirects stderr
file
being used stdout
.
Comments
Post a Comment