Skip to main content
Bash scripts do not need compiling. The Bash interpreter reads the script and executes its commands. Running a script normally starts a Bash process; sourcing it with source or . runs it inside the current shell. We mainly use Bash for automation, filtering and cron jobs.

The Shebang

An executable Bash script usually starts with this:
This tells the OS which interpreter to use when we run the file directly, for example with ./script.sh. We put it on the very first line. Another common form is #!/usr/bin/env bash, which finds Bash through the current environment. Other interpreted languages use the same shebang mechanism with their own interpreter. The shebang is not required when we explicitly pass the file to Bash:

if / elif / else

The fi closes the if block. We chain branches with elif and else:
One thing to note right away — the spaces separating [, its arguments and ] are required. Skip them and Bash interprets the text as a different command. Those [ ] brackets are not just decoration. What they actually are, we cover in the next part.