bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: argument precedence, output redirection


From: Eric Blake
Subject: Re: argument precedence, output redirection
Date: Fri, 03 Dec 2010 07:50:27 -0700
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101103 Fedora/1.0-0.33.b2pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.6

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]