bug-bash
[Top][All Lists]
Advanced

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

Error in manual for >&word redirection


From: Greg Wooledge
Subject: Error in manual for >&word redirection
Date: Wed, 12 Oct 2011 16:07:36 -0400
User-agent: Mutt/1.4.2.3i

The manual says:

    Redirecting Standard Output and Standard Error
      This construct allows both the standard output (file descriptor 1) and
      the standard error output (file descriptor 2) to be redirected to the
      file whose name is the expansion of word.

      There are two formats for redirecting standard output and standard
      error:

           &>word
      and
           >&word

The &>word part is correct:

imadev:~$ foo &>1
imadev:~$ cat 1
stdout
stderr
imadev:~$ rm 1

However, the >&word is not correct:

imadev:~$ foo() { echo stdout; echo stderr >&2; }
imadev:~$ rm 1
imadev:~$ foo >&1
stdout
stderr
imadev:~$ ls -l 1
1 not found

This is because >&filename and >&n conflict with each other.  If the word
is not a valid file descriptor number then the >&word part works as
advertised:

imadev:~$ foo >&xyzzy
imadev:~$ ls -l xyzzy
-rw-r--r--   1 wooledg    pgmr            14 Oct 12 15:58 xyzzy
imadev:~$ cat xyzzy
stdout
stderr

Even using a space is not sufficient to force a valid file descriptor number
to be treated as a filename:

imadev:~$ foo >& 1
stdout
stderr
imadev:~$ ls -l 1
1 not found

Personally I wish all the csh compatibility features would go away forever,
but I appreciate that it's too late to remove them at this point.  But
I think the manual should be updated to indicate that the >&word form
just plain fails for certain words, even with a space.



reply via email to

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