Tools#

The toolchain for shell scripts is mostly POSIX utilities you already have, plus a few well-known third-party programs.

Interpreter#

  • bash, GNU Bourne Again SHell. Default on most Linux systems.

  • sh , POSIX shell (often dash, ash, or busybox sh on minimal images).

Check the version:

$ bash --version

Linting#

$ shellcheck script.sh

Formatting#

  • shfmt, formatter for sh / bash / mksh.

$ shfmt -i 2 -ci -w script.sh

Testing#

$ @test "addition works" {
  $ run bash -c 'echo $((2 + 3))'
  $ [ "$status" -eq 0 ]
  $ [ "$output" = "5" ]
$ }

Debugging#

  • set -x , trace each command before it runs.

  • set -e , exit on the first failed command.

  • set -u , error on unset variables.

  • bash -x , run in trace mode without modifying the script.

  • bashdb , gdb-style debugger for Bash.

Editing#

Most editors have shell support out of the box. Useful add-ons:

  • bash-language-server, LSP backed by ShellCheck.

  • vim-shellcheck / VS Code “Bash IDE”, inline diagnostics.

Cross-Platform#

For scripts that target multiple shells, validate against POSIX with:

$ shellcheck -s sh script.sh
$ shfmt -ln posix -d script.sh