Lesson 23 / 29

Your First Bash Script

From a text file to an executable script.

The shebang

A script's first line, #!/bin/bash, tells the OS which interpreter should run it — this is the shebang.

Write and run it

Save the script, make it executable, then run it.

#!/bin/bash
echo "Hello, $(whoami)!"

Output:

Hello, alice!

chmod +x to run it

Save as greet.sh, run chmod +x greet.sh, then execute with ./greet.sh.