>In /bin/sh, I tried to redirect the standard error and standard output to
>/dev/null.
>I still has the error message from the following command:
> ls /xyz 2>&1 > /dev/null
>but not from the following command:
> ls /xyz 2>&- > /dev/null
>I thought >&1 is the same as >&-. Any comments are appreciated.
'>&-' closes stdout. Given
$ ls /etc/motd /etc/nonesuch
/etc/nonesuch not found
/etc/motd
you can throw away stderr by redirecting it to /dev/null,
$ ls /etc/motd /etc/nonesuch 2>/dev/null
/etc/motd
or throw away stdout by redirecting it to /dev/null,
$ ls /etc/motd /etc/nonesuch >/dev/null
/etc/nonesuch not found
or throw away both by redirecting stdout to /dev/null, and dup'ing
stderr to stdout.
$ ls /etc/motd /etc/nonesuch >/dev/null 2>&1
Note the difference between that command and
$ ls /etc/motd /etc/nonesuch 2>&1 >/dev/null
/etc/nonesuch not found
which dups stderr to stdout (probably the terminal), and then throws
away stdout.
--
Jim Davis | "You mean about your close personal relationship