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?

  • http://linux-training.be Paul Cobbaut

    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

  • http://www.vanginderachter.be/serge Serge van Ginderachter

    Paul, you’re doing this on mac? Try it on linux/ubuntu?

  • http://linux-training.be Paul Cobbaut

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

  • http://blog.vanderkussen.org Vincent Van der Kuss

    I’ve the same result as Paul on Fedora.

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

  • Jan Veldeman

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

    ls | xxd

    to see which character it is?

  • http://www.vanginderachter.be/serge Serge van Ginderachter

    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 0×20
    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?)

  • http://linux-training.be Paul Cobbaut

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

  • http://zeropoint.it Bart Van Loon

    I guess you must have typed ctrl-space or alt-space or something like that, no? :-)

  • Wouter Verhelst

    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

Analytics Plugin created by Web Hosting