The PATH Variable
PATH tells the shell where to look for commands.
View PATH
echo $PATH
Output: /usr/local/bin:/usr/bin:/bin:/home/student/.local/bin
Colons separate directories. The shell searches left to right.
Find where a command lives
which ls
which python3
which bash
whereis ls # Also shows man pages and source
type ls # Shows if it's a builtin, alias, or file
Add to PATH
export PATH="$PATH:/new/directory" # Temporary (this session)
export PATH="$HOME/.local/bin:$PATH" # Add to front (higher priority)
Make permanent
Add to ~/.bashrc:
export PATH="$HOME/scripts:$PATH"
Then reload:
source ~/.bashrc
Why does ./script.sh need the ./ ?
The current directory . is NOT in PATH by default for security. So to run script.sh in the current directory, you need:
./script.sh