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 array elements contain double quotes of their own.
As they say, if you think that's horrible, your life must be sweet indeed. Let's not let perfect be the enemy of good enough. If coping with unescaped double quotes is an issue, use printf '"%s" ' "${vals[@]//\"/\\\"}" ; echo instead to get a little farther. If you already have escaped double quotes, then you don't need it. If you can use this approach to get the problem solved, then use it. If not, try something else -- another tool, if necessary. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/