tech

Bash Scripting Tips

bashshellautomation

Shell scripts are the glue of development. Here are tips that save time.

Always Start With

#!/bin/bash
set -euo pipefail
  • -e: exit on error
  • -u: error on undefined variables
  • -o pipefail: fail if any command in a pipeline fails

Quote Everything

# Bad — breaks on spaces
rm $file

# Good
rm "$file"

These two habits eliminate most shell scripting bugs.