Strange

by Javantea
Jun 3, 2010

*nix have some strange concepts. This will be a brief blog because I have little to say. In the grep manual, I found a reference to an obscure option:

       -Z, --null
              Output  a  zero  byte  (the  ASCII  NUL  character) instead of the character that normally
              follows a file name.  For example, grep -lZ outputs a  zero  byte  after  each  file  name
              instead  of  the  usual  newline.   This  option makes the output unambiguous, even in the
              presence of file names containing unusual characters like newlines.  This  option  can  be
              used  with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary
              file names, even those that contain newline characters.

Did you read that? It's saying that you can have a newline in a filename, so I tested that out:

jvoss@localhost ~ $ touch 'blah
> yak
> dah'
jvoss@localhost ~ $ ls
Desktop                           j0anna1.crt           regdev
asos2l.txt                        j0anna1a.crt          src
blah?yak?dah                      j0anna1a1.crt         stage3-amd64-20090611.tar.bz2
emerge_kate1.txt                  libusb-1.0.8.tar.bz2  suzy_make.conf
emerge_kdebase-runtime-meta1.txt  lin2632.cfg           suzy_world.txt
emerge_kdebase-startkde1.txt      lin2632a.cfg          time1.py
emerge_konsole1.txt               media                 use1.txt
iwlist1.txt                       necessary.txt         wmii+ixp-3.9-2.tbz
iwlwifi-5000-ucode-8.24.2.12      portage-2010a.tgz     wpa_lev1.conf
iwlwifi-5000-ucode-8.24.2.12.gz   recent                xness.txt

See that blah?yak?dah file there? It's replacing newlines with ? because it doesn't want to display something else. That's probably very smart. Tab completion however, shows a completely different story:

jpico blah<tab>

jpico 'blah
yak
dah'

That's right, tab complete will put in newlines. How thoughtful. It makes sense if you think in terms of garbage in/garbage out.

How does jpico handle newlines in the filename?

         ^K cut line             ^W find first          ^J justify              ^X save or discard, exit
         ^U paste              ^W^W find next           ^T spell             Esc . for more help
    IW   blahJyakJdah                                                       Row 1    Col 1   11:37  Ctrl-G for help

Yep, instead of newline, jpico uses an underlined J in order to display newline in a filename. What happens when I try to save?

Name of file to save (^C to abort): dah
File dah2 saved

Nooo!!! Wrong answer! But wait, if I use the arrow keys, it goes to the previous line. That's actually a pretty decent way to do it. If you're expecting something like that...

Dear people of the Internet:
Expect newlines in filenames from now on.

Javantea 0 u t .

Permalink

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name