Linting
ShellCheck reports warnings and suggestions for Bash and sh scripts. shfmt formats them. This page is for developers who change the shell script or its tests in a project generated from Scaffold. Follow it to run both tools, fix the formatting and turn off a ShellCheck rule.
install.sh names the script after your project by default, such as acme-app.sh. On this page, use your script's name in place of shell-command.sh.
Check the scripts
To check the script and the .bash and .bats files in tests/bats:
-
Install ShellCheck and shfmt.
-
In your project root, run ShellCheck:
shellcheck shell-command.sh tests/bats/*.bash tests/bats/*.batsShellCheck reports the problems in each file.
-
Run shfmt with
-d:shfmt -i 2 -ci -s -d shell-command.sh tests/bats/*.bash tests/bats/*.batsshfmt prints a diff of the formatting changes it would make.
The Test shell workflow runs both tools in CI, with the same shfmt options.
Fix the formatting
To write the formatting changes back to each file, run shfmt with -w:
shfmt -i 2 -ci -s -w shell-command.sh tests/bats/*.bash tests/bats/*.bats
ShellCheck settings
To turn off a ShellCheck rule for a whole file, add a comment such as # shellcheck disable=SC2086 after the shebang line and before the file's first command. shell-command.sh uses this comment for SC2162.