Skip to content

bash redirection target gets funky

Can anybody explain me how this funky behaviour in bash works?

find /root  >output 2>error 3

Yes, that’s just “error” followed by a space followed by “3”.

serge@goldorak:~/tmp$ ls -l
total 8
-rw-rw-r-- 1 serge serge 71 Aug 30 13:57 error 3
-rw-rw-r-- 1 serge serge 6 Aug 30 13:57 output
serge@goldorak:~/tmp$

Lets create a file with a space in it:

serge@goldorak:~/tmp$ touch "test 1"
serge@goldorak:~/tmp$ ls -l
total 8
-rw-rw-r-- 1 serge serge 71 Aug 30 13:57 error 3
-rw-rw-r-- 1 serge serge 6 Aug 30 13:57 output
-rw-rw-r-- 1 serge serge 0 Aug 30 13:58 test 1
serge@goldorak:~/tmp$

using bash completion I get:

serge@goldorak:~/tmp$ ls -l test\ 1
-rw-rw-r-- 1 serge serge 0 Aug 30 13:58 test 1
serge@goldorak:~/tmp$ ls -l error 3
-rw-rw-r-- 1 serge serge 71 Aug 30 13:57 error 3
serge@goldorak:~/tmp$

It seems the space in “error 3″ is not a space but some other char?

9 Comments

  1. Paul Cobbaut wrote:

    I am unable to reproduce this:

    root@mac~/testf# find /root >output 2>error 3
    root@mac~/testf# ls -l
    total 6336
    -rw-r–r– 1 root root 37 Aug 30 16:10 error
    -rw-r–r– 1 root root 6481604 Aug 30 16:10 output

    Thursday, August 30, 2012 at 16:10 | Permalink
  2. Paul, you’re doing this on mac? Try it on linux/ubuntu?

    Thursday, August 30, 2012 at 17:07 | Permalink
  3. Paul Cobbaut wrote:

    No the Linux machine is named ‘mac’ because it is a Macbook Pro.

    Thursday, August 30, 2012 at 19:06 | Permalink
  4. I’ve the same result as Paul on Fedora.

    PS : your “Name” field does not allow me to fill in my complete name.

    Thursday, August 30, 2012 at 20:30 | Permalink
  5. Jan Veldeman wrote:

    I also couldn’t reproduce this.
    Have you tried:

    ls | xxd

    to see which character it is?

    Friday, August 31, 2012 at 08:44 | Permalink
  6. serge@goldorak:~/tmp$ ls error\ 2 | xxd
    0000000: 6572 726f 7220 320a error 2.
    serge@goldorak:~/tmp$ ls error 3 | xxd
    0000000: 6572 726f 72c2 a033 0a error..3.

    normal space is 0x20
    it seems in this special case i got a 0xc2a0 which is a “no break space”.

    It must have been some character I copy-pasted from the initial source (@Paul, maybe from the linux training pdf?)

    Friday, August 31, 2012 at 09:10 | Permalink
  7. Paul Cobbaut wrote:

    That example is not present in the pdf, I saw it first in your email…

    Friday, August 31, 2012 at 23:15 | Permalink
  8. I guess you must have typed ctrl-space or alt-space or something like that, no? :-)

    Saturday, September 1, 2012 at 18:13 | Permalink
  9. Wouter Verhelst wrote:

    Might want to add an “Update:” to your blog then, to make clear it’s not actually what you thought it was… that will prevent people from me being intrigued by what really is a case of PEBCAK ;-P

    Thursday, September 6, 2012 at 10:37 | Permalink

Analytics Plugin created by Web Hosting