# vim: ft=help:noml:

Word Expansions

  This clause describes the various expansions that are performed on words.
  Not all expansions are performed on every word, as explained later.

  Tilde expansions, parameter expansions, command substitutions, arithmetic
  expansions, and quote removals that occur within a single word expand to
  a single field.  It is only field splitting or pathname expansion that
  can create multiple fields from a single word.  The single exception to
  this rule is the expansion of the special parameter @ within double-
  quotes, as was described above.

  The order of word expansion is:

  1.  Tilde Expansion, Parameter Expansion, Command Substitution,
      Arithmetic Expansion (these all occur at the same time).

  2.  Field Splitting is performed on fields generated by step (1) unless
      the IFS variable is null.

  3.  Pathname Expansion (unless set -f is in effect).

  4.  Quote Removal.

  The $ character is used to introduce parameter expansion, command
  substitution, or arithmetic evaluation.

  Not all expansions are performed on every word, as explained later.

  Tilde expansions, parameter expansions, command substitutions, arithmetic
  expansions, and quote removals that occur within a single word expand to
  a single field.  It is only field splitting or pathname expansion that
  can create multiple fields from a single word.  The single exception to
  this rule is the expansion of the special parameter @ within double-
  quotes, as was described above.

  The order of word expansion is:
           a ⟨space⟩ if IFS is unset.

  @        Expands to the positional parameters, starting from one.
           When the expansion occurs within double-quotes, each
           positional parameter expands as a separate argument.  If
           there are no positional parameters, the expansion of @
           generates zero arguments, even when @ is double-quoted.
           What this basically means, for example, is if $1 is “abc”
           and $2 is “def ghi”, then "$@" expands to the two arguments:

               "abc" "def ghi"

  #        Expands to the number of positional parameters.

  ?        Expands to the exit status of the most recent pipeline.

  - (Hyphen.)  Expands to the current option flags (the single-letter
           option names concatenated into a string) as specified on
           invocation, by the set builtin command, or implicitly by the
           shell.

  $        Expands to the process ID of the invoked shell.  A subshell
           retains the same value of $ as its parent.

  !        Expands to the process ID of the most recent background
           command executed from the current shell.  For a pipeline,
           the process ID is that of the last command in the pipeline.

  0 (Zero.)   Expands to the name of the shell or shell script.
