see each command a script runs

Debug a script: print every command as it runs, check its syntax, find common mistakes.

  • shell
  • development

Steps

  1. bash -x script.sh

    run it, printing each command first

  2. set -x

    inside the script: print from here on; set +x stops

  3. bash -n script.sh

    check the syntax without running it

  4. shellcheck script.sh

    the usual mistakes, with how to fix them (shellcheck)

Commands used

  • bash
  • shellcheck

Each has a page in lore: lore bash opens it.