Robust Scripts
Strict Mode
Safer Defaults
Strict shell options turn common scripting mistakes into early failures. Defaults keep missing inputs explicit without weakening the script.
Program
Play the script to watch a missing argument become a default value, then become a filename-safe slug.
strict_mode.sh
#!/usr/bin/env bash
set -euo pipefail
input="${1:-draft report}"
safe="${input// /_}"
echo "$safe"
strict mode
`set -euo pipefail` makes failed commands, unset variables, and failed pipelines visible.
default expansion
`${1:-draft report}` supplies a value when the first argument is missing or empty.
substitution
`${input// /_}` replaces every space in the value.