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

2009-11-24 Thread Antonio Macchi
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')
  0a|.|
0001



$'\x01' outputs twice.

$ hd <(echo -n $'\x01')
  01 01 |..|
0002



thanks for your great job
have a nice day

(God Save Linux!)

bye




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

2009-11-24 Thread Maarten Billemont
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')
>   0a|.|
> 0001
> 
> 
> 
> $'\x01' outputs twice.
> 
> $ hd <(echo -n $'\x01')
>   01 01 |..|
> 0002
> 
> 
> 
> thanks for your great job
> have a nice day
> 
> (God Save Linux!)
> 
> bye
> 
>