[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf "%q" and $'...'
From: |
Antonio Macchi |
Subject: |
Re: printf "%q" and $'...' |
Date: |
Wed, 25 Nov 2009 16:27:06 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.19 (X11/20090103) |
When you run read -d $'\x00' what you're really doing is setting up
a bunch of C-strings in memory like this:
+-+-+-+-+--+-
|r|e|a|d|\0|
+-+-+-+-+--+-
+-+-+--+-
|-|d|\0|
+-+-+--+-
+--+--+-
|\0|\0|
+--+--+-
WOW!
but...
$ printf one$'\x00'two\\n
+-+-+-+-+-+-+--+
|p|r|i|n|t|f|\0|
+-+-+-+-+-+-+--+
+-+-+-+--+-+-+-+--+--+
|o|n|e|\0|t|w|o|\n|\0|
+-+-+-+--+-+-+-+--+--+
so the output should be "one", and stop here!
but the real output is
onetwo
so, imho, there's something more...
imadev:~$ echo $'foo\0bar'
foo
sorry... I'm a little bit confusing... look
$ echo foo$'\0'bar
foobar
- Re: printf "%q" and $'...', (continued)
Re: printf "%q" and $'...', Antonio Macchi, 2009/11/25
Message not available
Message not available
Message not available