ShellCheck in Termux – Find Errors in Shell Scripts

ShellCheck is a command-line tool that checks shell scripts for errors and common mistakes. It can detect syntax problems, suspicious commands, and other issues in Bash and shell scripts. It also provides suggestions to improve your scripts and make them easier to maintain.

Here’s what you can do with ShellCheck in Termux:

  • Check shell scripts for common errors.
  • Find syntax problems and suspicious commands.
  • Detect incorrect variable usage.
  • Get suggestions to improve shell scripts.
  • Check Bash, sh, dash, ksh, and BusyBox scripts.
  • Display warnings with different severity levels.
  • Generate reports in JSON, GCC, and other formats.
  • Enable additional checks for deeper analysis.
  • Check sourced files and external scripts.

Install ShellCheck in Termux

You can easily install ShellCheck on Termux using the following command below. Just copy and run it in your Termux terminal.

First, update and upgrade the packages:

pkg update && pkg upgrade -y

Install ShellCheck:

pkg install shellcheck -y

Once the installation is complete, ShellCheck is ready to use.

Use ShellCheck in Termux

After installing ShellCheck, you can start checking your shell scripts for errors and common mistakes using the useful commands below.

Check a shell script:

shellcheck script.sh

Check multiple shell scripts:

shellcheck script1.sh script2.sh

Check a script using Bash:

shellcheck -s bash script.sh

Check a script using the sh shell:

shellcheck -s sh script.sh

Check sourced files:

shellcheck -a script.sh

Enable color output:

shellcheck -C always script.sh

Disable color output:

shellcheck -C never script.sh

Show only specific warning types:

shellcheck -i SC2086,SC2046 script.sh

Exclude specific warning types:

shellcheck -e SC2086 script.sh

Set the minimum warning severity:

shellcheck -S warning script.sh

You can also use error, info, or style as the severity level.

Generate a JSON report:

shellcheck -f json script.sh

Generate a GCC-style report:

shellcheck -f gcc script.sh

Display available optional checks:

shellcheck --list-optional

Enable all optional checks:

shellcheck -o all script.sh

Enable external source checking:

shellcheck -x script.sh

Skip local configuration files:

shellcheck --norc script.sh

Specify a shell configuration file:

shellcheck --rcfile=.shellcheckrc script.sh

Set the source path for included files:

shellcheck -P SCRIPTDIR script.sh

Show the installed version:

shellcheck --version

Show the help menu:

shellcheck --help

These commands let you check shell scripts, find common mistakes, control warning levels, and generate reports in different formats.

End Note

ShellCheck is a useful tool for finding syntax errors, common mistakes, and suspicious commands in your shell scripts, and you can use it to check your own scripts before running or sharing them to make sure your code is clean and works as expected.

SHARE THIS POST: