Shell Scripting for Beginners / Chapter 1 — Running it as a script (lessons 1–3) / Lesson 1

The shebang and the execute bit

Time needed: about 8 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

The first wall is nearly always in the same place

You gather the commands you have been typing into a file, run ./run.sh, and nothing works.

It says Permission denied.

You copy an article exactly and get bad interpreter.

The first wall in shell scripting is nearly always right here.

This lesson pins down what the #! on line one actually does, by running it.

By the end you can explain for yourself why ./ is required, and whether to write #!/bin/bash or #!/usr/bin/env bash.

hello.sh

#!/usr/bin/env bash # Your first one. Start by getting this to run. echo "Hello, shell script" echo "Shell currently running: $BASH" echo "Version: $BASH_VERSION"

Terminal

$ chmod +x hello.sh $ ./hello.sh Hello, shell script Shell currently running: /opt/homebrew/bin/bash Version: 5.3.15(1)-release

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.