Consider the 2 bash commands below:
$ VAR="hello world"
$ ./script.sh "$VAR"
Line 1 stores the string hello world (quotes removed) to parameter VAR.
Line 2 should be processed as follows:
- 2 tokens result from tokenization stage (token 1 is
.\script.shand token 2 is"$VAR") - Parameter and variable expansion applies to token 2 (
"$VAR"gives"hello world") - Word splitting does not apply to
"hello world"due to the double quotes ("hello world"remains one word) - Quote removal occurs and removes the double quotes around
"hello world"Upon execution, we should havehello worldbeing passed as a single argument to./script.sh.
Hence, there should be one unique positional parameter $1 which is being assigned the unique word hello world.
QUESTIONS
- Precisely, at what stage of command evaluation order does
$1get assigned its value? - In case this happens after quote removal, what mechanism helps the shell keep track of what constitutes an argument?
- Does the shell store an indexed representation of the final list of words (post-expansion)?