Re: Yet another quoting question

2011-05-09 Thread Peggy Russell
> For straight debugging output, it's probably ok. You might have to > play with it a little if you want to make it into something you can > eval from a command substitution to copy an array. Just another thought, declare -p aa is nice for debugging arrays. help declare ... -pdisplay t

Re: Yet another quoting question

2011-05-06 Thread Chet Ramey
On 5/6/11 12:00 PM, Greg Wooledge wrote: > On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: >> Eric suggested %q, and that works to a >> certain degree, but you can also use >> >> printf '"%s" ' "${vals[@]}" ; echo >> >> and get the double-quoting you want. > > Fails horribly if the arr

Re: Yet another quoting question

2011-05-06 Thread Steven W. Orr
On 5/6/2011 12:05 PM, Chet Ramey wrote: On 5/6/11 12:00 PM, Greg Wooledge wrote: On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: Eric suggested %q, and that works to a certain degree, but you can also use printf '"%s" ' "${vals[@]}" ; echo and get the double-quoting you want. Fa

Re: Yet another quoting question

2011-05-06 Thread DJ Mills
On Fri, May 6, 2011 at 12:00 PM, Greg Wooledge wrote: > On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: > > Eric suggested %q, and that works to a > > certain degree, but you can also use > > > > printf '"%s" ' "${vals[@]}" ; echo > > > > and get the double-quoting you want. > > Fails

Re: Yet another quoting question

2011-05-06 Thread Chet Ramey
On 5/6/11 12:00 PM, Greg Wooledge wrote: > On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: >> Eric suggested %q, and that works to a >> certain degree, but you can also use >> >> printf '"%s" ' "${vals[@]}" ; echo >> >> and get the double-quoting you want. > > Fails horribly if the arr

Re: Yet another quoting question

2011-05-06 Thread Greg Wooledge
On Fri, May 06, 2011 at 11:50:34AM -0400, Chet Ramey wrote: > Eric suggested %q, and that works to a > certain degree, but you can also use > > printf '"%s" ' "${vals[@]}" ; echo > > and get the double-quoting you want. Fails horribly if the array elements contain double quotes of their own. Re

Re: Yet another quoting question

2011-05-06 Thread Chet Ramey
On 5/6/11 11: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. > > I wanted to write a routine to print out an array. It just takes the name > of the array as an argument. Bec

Re: Yet another quoting question

2011-05-06 Thread Greg Wooledge
On Fri, May 06, 2011 at 11:02:32AM -0400, Steven W. Orr wrote: > I wanted to write a routine to print out an array. It just takes the name > of the array as an argument. Flee in terror. Do not look back. Oh, wait, you want a useful answer? Switch to ksh93 and use nameref. You CANNOT do this sa

Re: Yet another quoting question

2011-05-06 Thread Eric Blake
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'