On 05/06/2011 09:02 AM, Steven W. Orr wrote:
>  4.0.35(1)-release (x86_64-redhat-linux-gnu)
> 
> I have a bunch of arrays, and some of the arrays' values are null or
> might contain spaces.

printf %q is your friend.

$ a[0]=aaa a[1]= a[2]='bbb  ccc'
$ printf '%q ' "${a[@]}"
aaa '' bbb\ \ ccc

> I'd love to see an elegant solution. :-)

OK, so printf %q prefers '' and \ over "", but the end result is an
unambiguous array listing that can be fed back into shell code.

-- 
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to