Hi Chet,
> > I wrote:
> >> Stackoverflow [1] says that word-expansion must be
> >> avoided, because it does not support the spaces in arguments
> >
> > These two examples show how non-intuitive shell scripts behave,
> > regarding spaces and backslashes in arguments:
> >
> > $ printf '%s\n' a\\bc\ d\\ef
> > a\bc d\ef
> >
> > $ var='a\\bc\ d\\ef'
> > $ printf '%s\n' $var
> > a\\bc\
> > d\\ef
> >
> > Good luck understanding this!
>
> Word splitting and quote removal aren't that bad.
The inconsistency between these two examples, regarding word splitting
and quote removal, is only a minor problem, because it is easy to avoid it:
just
1. use double-quotes around every variable reference,
2. use `...` and $(...) only on the right-hand side of variable assignments.
The major problem (with POSIX sh) is that
* it is hard to have a "list of arbitrary strings" data type, i.e. assign
a list of arbitrary strings to a single shell variable,
* doing so requires a dangerous primitive named 'eval',
* for three different special cases of this problem, simple-to-use solutions
have been designed and implemented:
- lists of simple words: e.g. var="word1 word2 ... wordN".
- a limited number of words: e.g. var_part1, var_part2, ..., var_part5.
- a single list of arbitrary strings: e.g.
set x "$@" "word1"
set x "$@" "word2"
...
set x "$@" "wordN"
but the general solution of the problem has not become simpler by these
limited-case "solutions".
It is quite well possible that array variables, as supported by bash and zsh,
are the solution. Unfortunately, they are not standardized by POSIX and thus
not portable. [1]
Bruno
[1]
https://git.savannah.gnu.org/gitweb/?p=gnulib/maint-tools.git;a=blob;f=test-programs/sh-features;h=ff7d4b6fa29c58da4fbec47a5e78a63f9673670c;hb=HEAD#l152