On 12/03/2010 07:46 AM, Payam Poursaied wrote:
>
> Hi all,
> I'm not sure this is a bug or please let me know the concept:
> What is the difference between:
> ls -R /etc/ 2>&1 1>/dev/null
> and
> ls -R /etc/ 1>/dev/null 2>&1
POSIX requires that redirections are evaluated from left to right.
The first line duplicates fd 2 from 1 (that is, stderr is now shared
with stdout), then changes fd 1 onto /dev/null (so you've silenced
stdout, and errors from ls will show up on your stderr).
The second line changes fd 1 onto /dev/null, then duplicates fd 2 from 1
(that is, stderr is now shared with /dev/null, and you've silenced all
output to either stream).
> the second one redirect everything to /dev/null but the first one, still
> prints errors (run as a non root user would unveil the problem)
> it the order of arguments important? If yes, what is the idea/concept behind
> this behavior?
Yes the order is important, and the idea behind the behavior is that
left-to-right evaluation order can be easily documented and relied on.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc Description: OpenPGP digital signature