Skip to main content

Quoting and Not Quoting Arguments

Word splitting

Bash shell and zsh shell will scan results of

  1. Parameter expansion: $PATH
  2. Command substitution: $(echo hi)
  3. Arithmetic expansion: $((x += 1))

For word splitting if they DO NOT occur within double quotes.

Basically with word splitting the shell will treat whatever is in $IFS as delimiter for word splitting, it is usually spaces, newline, and tab. It will split those results into different arguments for example "one two three" will become three parameter and be passed into whatever the program it is invoked with. For example

args="one two three"
./myprogram $args

myprogram will be passed a total of THREE arguments, "one", "two", and "three" respectively. However, if you do ./myprogram "$args" it will instead be passed with only one argument.