Ravindra BagaleCourses & study guides

Chapter 5: Bash Scripting for Automation

5.2 Shebang, permissions, first script

Start every script with a shebang so the OS knows which interpreter to use:

#!/usr/bin/env bash
set -euo pipefail
Piece Meaning
#!/​usr/​bin/​env bash Run with Bash found on PATH
set -e Exit if a command fails
set -u Exit if you use an unset variable
set -o pipefail Fail if any command in a pipeline fails

set -euo pipefail is a safety habit for new scripts. You can relax it later when you knowingly handle errors.

Steps — hello script

  1. Create hello.sh with the shebang and echo "badge API script ok".
  2. Make it executable for you: chmod u+x hello.sh (owner execute only — enough for labs).
  3. Run: ./hello.sh
  4. Confirm you see the message.

What you see: one line of output. If you get "Permission denied", the execute bit is missing. If you get "command not found" without ./, you forgot the path prefix.

Ravindra Bagale's Tip

Script bash hello.sh ne pan chalte — pan ./hello.sh shebang + execute bit practice karte. Team madhe executable scripts common aahet. Lakshat theva!