[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Word splitting
From: |
Paul Wagner |
Subject: |
[Help-bash] Word splitting |
Date: |
Thu, 03 Oct 2019 13:48:08 +0200 |
User-agent: |
Posteo Webmail |
Hello Bashonados,
apologies in case this question has been answered before, or if the
answer is all too obvious, I haven't been able to google a satisfying
solution.
Sometimes I would want bash to 'honor' quotes inside parameter
expansions, i.e. treat quotes inside an expansion not as literal, but as
syntactical, in order to prevent word splitting inside pairs of those
quotes.
Example:
$ s='aaa "bbb ccc" ddd'
$ for p in xxx $s zzz; do echo $p; done
obviously gives
xxx
aaa
"bbb
ccc"
ddd
zzz
How can I instruct bash to give
xxx
aaa
bbb ccc
ddd
zzz
My practical solution would be arrays, but that feels not very elegant,
and I found a rather theoretical one (as it only works in my minimal
example) to be
$ eval "for p in xxx $s zzz; do echo \$p; done"
Is there any smart, more general way to do this?
Thanks for your help,
Paul
- [Help-bash] Word splitting,
Paul Wagner <=