Quote:
Originally Posted by Linunix
Thanks!
I read that before but I wonder if it's implemented because it can't produce any difference to "$*" with "$@" or ""$@"".
For instance I tried
Code:
echo "cmdline \$@ = "$@""
echo "$@" > clfile
cat clfile
but I don't receive any quoted arguments.
|
Ah, I think I understand better what you are trying to do now.
The quotes themselves have meaning only for the shell which encounters them (i.e. the shell that invokes the first script), and as already pointed out, should not be thought of as delimiters so much as an escaping mechanism. Again, from man bash:
Code:
QUOTING
Quoting is used to remove the special meaning of certain characters or words to
the shell.
...
There are three quoting mechanisms: the escape character, single quotes, and dou‐
ble quotes.
So the first application never sees the quotes themselves (their
special meaning was for the invoking shell), the target script only receives the (previously escaped)
values. When you then pass those values on within your script such as via
"$@", you pass on the
received meaning of those parameters, but not any escaping mechanism used to allow you to receive them. If the original parameter was empty (i.e. nothing ordinary and nothing escaped) then you pass on that same
nothing to the next application. The quotes in
"$@" again have meaning to the current shell, not the shell in which the constructed command is executed, and not to the target script.
If for some reason you really needed to pass
something instead of nothing for those received empty parameters, it would be up to your first application to escape the
nothings it had received into
something that can be passed along to the next application, perhaps by finding the empty ones and replacing them with a set of escaped quotes,
\"\". Then the current shell would ignore the special meaning of quotes, the shell in which the next command is executed would see the empty quotes as an escaped nothing and pass along an empty parameter, and the target script would receive the meaning of an empty positional parameter.
Hope that makes sense!