[Top][All Lists]

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

Re: argument precedence, output redirection

From: Chet Ramey
Subject: Re: argument precedence, output redirection
Date: Fri, 3 Dec 2010 09:50:08 -0500

> 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
> 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?

Redirections are processed left-to-right (or, if you prefer, beginning to end).
The manual page has this to say:

       Note  that  the order of redirections is significant.  For example, the

              ls > dirlist 2>&1

       directs both standard output and standard error to  the  file  dirlist,
       while the command

              ls 2>&1 > dirlist

       directs  only the standard output to file dirlist, because the standard
       error was duplicated as standard output before the standard output  was
       redirected to dirlist.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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