On Thu, Oct 03, 2019 at 01:48:08PM +0200, Paul Wagner wrote:
> Example:
>
> $ s='aaa "bbb ccc" ddd'
> $ for p in xxx $s zzz; do echo $p; done
No. Use an array.
Also, learn how to quote correctly. echo $p is a huge danger sign.
https://mywiki.wooledge.org/BashPitfalls#pf14https://mywiki.wooledge.org/Quotes
> My practical solution would be arrays, but that feels not very elegant,
Adjust your brain until it feels elegant, because it's the correct
solution.
s=(aaa "bbb ccc" ddd)
for p in xxx "${s[@]}" zzz; do echo "$p"; done
# ... or ...
printf '%s\n' xxx "${s[@]}" zzz
If you can't live with this, then stop using bash. Use a language
that better matches your needs. Have you considered Tcl?
% set s {aaa {bbb ccc} ddd}
aaa {bbb ccc} ddd
% puts [join [concat xxx $s zzz] \n]
xxx
aaa
bbb ccc
ddd
zzz
If you don't like that, there's Python, Ruby, Perl, ....