Skip to content

Instantly share code, notes, and snippets.

@ArloL
Last active September 9, 2023 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArloL/f56c25ac6bbb1b0bc494 to your computer and use it in GitHub Desktop.
Save ArloL/f56c25ac6bbb1b0bc494 to your computer and use it in GitHub Desktop.
Effortful Retrieval Questions for Writing Robust Bash Shell Scripts

Writing Robust Bash Shell Scripts

http://www.davidpashley.com/articles/writing-robust-shell-scripts/

  1. How can you tell bash to exit when a variable is unitialised?
  2. How can you tell bash to exit when a command fails?
  3. How can you execute a command that fails in that scenario?
  4. How can you tell bash to exit when a pipe command fails?
  5. How do you create a directory?
  6. How do you delete a file?
  7. How to compare a variable that may contain spaces?
  8. Should you write $@ or "$@"?
  9. How can you execute code on failure?
  10. How should you make changes to many files?
  11. What are the downsides of this approach?
  12. What should be checked after making the change?
  1. set -o nounset or set -u
  2. set -o errexit or set -e; command || true
  3. set -o pipefail
  4. mkdir -p dir or mkdir --parents dir
  5. rm -f file
  6. if [ "$hello" = "hello" ]
  7. "$@"
  8. trap "rm -rf $lockfile; exit" INT TERM EXIT
  9. Copy files first and move back. Move is atomic.
  10. Duplicate data
  11. Open file handlers. lsof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment