Reputation: 1
I want to find out how many arguments are passed to the command by the shell:
echo "It's "'funny how'" it's done."
It is 1 argument, because first ' turn off the " after s , and the ' after turn off following " , so first " matches the last ".
For
"<bar bar -b "-a" '-r' >bar bar bar"
I don't understand why 5 argument are passed to the command by shell
pig pig pig
6 arguments passed to command by shell
Upvotes: 0
Views: 89
Reputation: 14452
Bash converts its input to tokens based on the sequence
Applying the above to the: echo "It's "'funny how'" it's done."
:
It's*
funny*how
*it's*done.
It's*funny*how*it's*done.
Note that quoting are not nested, as implied by the question (e.g., single quote within double quotes does NOT have special meaning).
Following on <pig pig -x " " -z -r" " >pig pig pig
('*' is quoted space, '_' is unquoted space).
de-quoting will result in 2 replacements ('*' indicate quoted space)
<pig_pig_-x_
2, Double quoted *
_-z_-r
*
Word splitting will process the combined <pig_pig_-x_*_-z_-r*_>pig_pig_pig
. Splitting on unquoted spaces: "pig", "pig", "pig". The 'pig' will be processed by the shell: redirect input and output. Resulting in 7 parameter.
Upvotes: 1