All POSIX-compliant Shell Command Language shells support set -n , which can be used to verify script syntax. Therefore, you can add
set -n
so that your code syntax checks it. Also note that the standard sh utility is also required to support the -n command line -n , which has equivalent semantics for using set -n , Bash, and possibly other shells also support this command line flag. Therefore, you can simply run the syntax of the following form: script:
sh -n yourScriptFilename.sh
WARNING: This does not guarantee you that the script has fully POSIX compatible syntax. For example, Bash allows bahisms (for example, arrays and c{a,u}t ) to go unnoticed even when using the --posix command line (and / or +B ) in addition to -n when calling sh . Other shells may have similar problems.
source share