A script is a text file with a shebang and shell commands. Scripts make repeatable what you would otherwise retype—deploy steps, backups, and local dev setup.
Minimal script structure
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
echo "Starting deploy..."
echo "Done."set -euo pipefail is a common safety trio: exit on error, error on unset vars, fail pipelines on first error.
Running scripts
./deploy.sh # needs execute bit
bash deploy.sh # runs with bash even without +xPrefer explicit bash script.sh in docs when execute bit might be missing.
Debugging
bash -x deploy.sh # trace each command
set -x # enable tracing inside script
set +x # disable tracingTracing helps debug CI failures—compare with logs from Git CI lessons later.
Important interview questions and answers
- Q: What does set -e do?
A: Exit immediately if a command returns non-zero (with exceptions for some contexts). - Q: bash script.sh vs ./script.sh?
A: The former needs no execute bit; the latter requires +x and honors shebang.
Self-check
- Name three flags in the safety trio set -euo pipefail.
- What flag prints commands as they run?
Tip: Start serious scripts with set -euo pipefail and a comment describing required tools.
Interview prep
- set -e?
Exit script when a command fails.
- bash -x?
Print commands before execution (trace).