Kolam Ayer MakersLinux Foundations

Shebang

Core Idea

A shebang is the first line of an executable script that tells the kernel which interpreter should run the file.

Shape

#!/bin/bash

The first two characters must be #!. The path after them must point to an interpreter. In this course, Bash scripts use /bin/bash.

Why It Matters

These two commands are different:

bash ~/scripts/hello.sh Makers
~/scripts/hello.sh Makers

The first command explicitly runs Bash and gives it the script. The second asks the system to execute the file directly. Direct execution needs executable permission and a valid shebang so the system knows which interpreter to start.

Safe Script Header

#!/bin/bash
set -euo pipefail

Use this at the top of course Bash scripts unless a quest says otherwise.

Common Failures

CRLF Check

If a script copied from another system behaves strangely:

head -n 1 script.sh | xxd

If the line ends in 0d 0a, it has Windows CRLF line endings. Recreate the first line in the terminal editor or ask before doing bulk conversion.

Proof Check

Create a tiny script with #!/bin/bash, add chmod +x, run it directly, then run the same script with bash script.sh. Explain which command used the shebang.

Docs Pointers