On Tuesday, 7 July 2015 07:45:52 UTC+5:30, Kaz Kylheku wrote:
> On 2015-07-07, Martijn Dekker <
mar...@inlv.demon.nl> wrote:
> > In article <
271492cd-5d29-4db9...@googlegroups.com>,
> > Rakesh Sharma <
shar...@hotmail.com> wrote:
> >
> >> Make sure to quote the arguments to avoid
> >> word splitting's mal-effects. That is,
> >>
> >> > > $(printf 'server -entry %s\n' "$@")
> >>
> >> $(printf 'server -entry "%s"\n' "$@")
> >
> > That argument was already quoted with single quotes. The double quotes
> > around the %s aren't quoting an argument, but are part of the
> > single-quoted argument, so they will become part of each line of output.
>
> The output, however, resembles a command, which suggests that it will
> be subject to evaluation by the shell, at which point it matters.
The output, howsoever it appears, will be sent to the shell for evaluation
as it's enrobed in $().
And then if the shell can't make sense of it shall barf.
> (Whether simply wrapping the interpolated text with double quotes is
> sufficient depends on the text, of course.)
You're absolutely correct. We are in the eval land here, so it's the user's
responsibility to quote right before handing over to the shell. In such
a scenario, it's best to use single quotes. Why? because no character is
special within single quotes. But whatif there's a single quote in the params? We need to special case this otherwise the shell will trip up.
change each ' ---> '\'' wherever present.
$(printf "server -entry '%s'\n" "$@")
Inside each of the parameters contained in "$@" we need to
quote all the single quotes in the manner prescribed above.
For more info
https://groups.google.com/forum/#!searchin/comp.unix.shell/re-quoting$20Rakesh/comp.unix.shell/3PC4RTzaFKw/GSvrn6-ISEIJ