On Fri, Mar 16, 2018 at 08:18:53PM +0100, d...@ftb-esv.de wrote: > Command: x="a b c"; echo "'${x// /','}'" > On old systems the output is: 'a','b','c' > In this version the output is: 'a,b,c'
So, this LOOKS like an attempt to take a list, and write it out with single quotes around each element, and commas BETWEEN the quoted elements (but no trailing or leading comma). Obviously this is not the best way to store a list, nor is it the best way to write a list to stdout with those modifications. If you want to continue along these cheap hack lines, then you need to store the quote character in a variable, and use that inside the parameter expansion. Thus: wooledg:~$ string="a b c"; q=\'; echo "'${string// /$q,$q}'" 'a','b','c' But this is really not the way I would approach the problem. Granted, bash is not a great language for operating on lists, but still.... Printing a list, with modifications, WITH an extra trailing comma, is trivial: wooledg:~$ list=(a b c); printf "'%s'," "${list[@]}"; echo 'a','b','c', Given this, probably the *easiest* way to get the desired result without the extra trailing comma would be to remove it afterward: wooledg:~$ list=(a b c); printf -v tmp "'%s'," "${list[@]}"; echo "${tmp%,}" 'a','b','c' I would probably go with that, if I had to do this in bash.