bug-bash
[Top][All Lists]
Advanced

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

Re: printf "%q" and $'...'


From: Maarten Billemont
Subject: Re: printf "%q" and $'...'
Date: Wed, 25 Nov 2009 08:25:00 +0100

As for NUL out outputting anything in your result, the cause is C-strings.  
Arguments are C-strings and those are delimited by NUL bytes.  Therefore, the 
NUL byte that you're putting in it is actually marking the end of the string.  
So the argument ends BEFORE your NUL byte.  So it's empty.

As or \x0a, that's a newline.  And command substitution trims trailing 
newlines.  So a string "[newline]" gets trimmed to "".

On 25 Nov 2009, at 08:19, Antonio Macchi wrote:

> Hi, I'm using older bash 3.2.39, so please forgiveme if in your newer bash 
> this issue does not arise.
> 
> 
> 0x00 and 0x0a has no output in printf "%q"
> 
> $ for i in {0..9} a; do printf "%q\n" "`echo -en \"\x0$i\"`"; done
> ''
> $'\001'
> $'\002'
> $'\003'
> $'\004'
> $'\005'
> $'\006'
> $'\a'
> $'\b'
> $'\t'
> ''
> 
> ------------
> 
> $'\x00' outputs nothing
> 
> hd <(echo $'\x00')
> 00000000  0a                                                |.|
> 00000001
> 
> ------------
> 
> $'\x01' outputs twice.
> 
> $ hd <(echo -n $'\x01')
> 00000000  01 01                                             |..|
> 00000002
> 
> 
> 
> thanks for your great job
> have a nice day
> 
> (God Save Linux!)
> 
> bye
> 
> 





reply via email to

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