bug-bash
[Top][All Lists]
Advanced

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

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


From: Lhunath (Maarten Billemont)
Subject: Re: printf "%q" and $'...'
Date: Wed, 25 Nov 2009 15:22:09 +0100

On 25 Nov 2009, at 14:58, Antonio Macchi wrote:

> my goal is very very stupid, like this
> 
> $ printf "%q" $(</bin/ls)
> 
> to get a "ascii form" of a binary file (something like uuencode)
> 
> 
> but, as you can see, it does not work only for two binary chars
> 
> 0x00, and 0x0a

That doesn't sound like a goal; more like an approach to achieve some other 
goal.

1. Remember to quote your expansions: "$(..)"
2. You can't put binaries in arguments for the very reason you just 
encountered:  Arguments cannot hold NUL bytes.

If you state the true goal (why are you trying to convert binary files into 
some sort of undefined form?) perhaps a more appropriate suggestion can be made.

printf doesn't read from a stream, so you can't use it to %q-encode your binary 
data directly.  Though %q-encoding binary data sounds like an odd requirement.  
You did mention uuencode so I assume you considered that already as well as 
base64 encoding and found it insufficient.  Which leaves me wondering what you 
could possibly be trying to do.



reply via email to

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