Shell Processing Order#

The logical sequence Bash follows when processing a command.

Tokenization#

The shell reads the input and breaks it into tokens based on metacharacters.

Alias Expansion#

Checks if the first word of the command is an alias and replaces it.

  • Bypassing Aliases:
    • \COMMAND: Using a backslash (eg. \ls) bypasses aliases.
    • command COMMAND: Using the command built-in bypasses both aliases and shell functions, ensuring the system binary or built-in is executed.

Expansion#

Expansions are performed in the following order:

  1. Brace Expansion ({ })
  2. Tilde Expansion (~)
  3. Parameter/Variable Expansion ($), Command Substitution ($( )), and Arithmetic Expansion ($(( ))) — these are performed at the same time.
  4. Word Splitting
  5. Pathname Expansion (Wildcards *, ?)

Redirection#

The shell handles I/O redirections (<, >, >>, etc.).

Execution#

The shell searches for the command in this order:

  1. Functions
  2. Built-ins
  3. Executables (searching through PATH)