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
- Create
hello.shwith the shebang andecho "badge API script ok". - Make it executable for you:
chmod u+x hello.sh(owner execute only — enough for labs). - Run:
./hello.sh - 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!