Expansion & Substitution

Before the shell executes your command, it performs a process called Expansion. This allows you to use shorthand symbols that the shell expands into full names or values.

1. Pathname Expansion (Wildcards)

Wildcards allow you to select multiple files based on patterns.

Bash

# List all files ending in .txt
ls *.txt

# List all files starting with 'data'
ls data*

# List files like 'file1.txt', 'file2.txt' but not 'file10.txt'
ls file?.txt

2. Tilde Expansion (~)

The ~ symbol is a shorthand for your Home directory.

Bash

cd ~/Documents

3. Arithmetic Expansion

The shell can perform basic math using the $(( )) syntax.

Bash

echo $(( 5 + 10 ))

4. Command Substitution

This allows you to take the output of one command and use it as an argument for another command using the $( ) syntax.

Bash

echo "Today is $(date)"