On Wed, Apr 4, 2012 at 10:07 AM, Greg Wooledge <address@hidden>
There is no white space character anywhere. The unquoted parameter
expansion results in a list of words, and each word becomes one argument.
I realize I explained it wrong.
Let me try again.
With 2 files in the directory, one named * and the other named nonAsterisk, the for loop:
for file in *; do
produces file='*' on the first pass.
The echo statement contains the unquoted $file which bash expands to 2 parameters namely * and nonAsterisk.
Same goes for the func line.
Therefore these 2 statements get 2 passed parameters which is what I wanted, and got.
Am I right so far? If so, then quoting is still optional isn't it?
echo $foo is always wrong because it never reproduces the content of
$foo correctly (except in degenerate cases). The point of echo being
to present information to a human being, an echo that produces the
wrong information is horribly bad.
OK In the strictest sense you're right, but my example is contrived.
> That's why I eventually put double quotes around the second version to show
> only 1 parm is hitting echo and the function. That parm has a space in it.
You're confused. The only way there can be a space in the argument to
the function in this code:
Yes - I made a mistake in my original explanation that I now corrected. I see you're correct.
If you are still confused about showing arguments, put markup around them
so you can be certain of what you are getting. I use this script:
imadev:~$ cat bin/args
printf "%d args:" $#
printf " <%s>" "$@"
I habitually use echo when printf is so much more capable. Old habits die hard. I'll try switching to printf because it allows for the easy placement of, in your case, the less & greater symbols that automatically repeat if necessary. Can't get that from echo.