bash -n
Running bash with -n, which reads and parses a script but runs nothing, reporting syntax errors only.
In more detail
It is safe even on a script you do not trust or that deletes files, because no command executes. It cannot find mistakes that only show up at run time, such as a misspelled command.
Example
bash -n broken.shRelated terms
- syntax error — A mistake in the form of code, such as an unclosed bracket or an if without its matching end, that the language cannot understand and so will not run.
- bash -x — Tracing mode, turned on with bash -x or set -x, in which bash prints each command after expansion, just before running it.
- ShellCheck — A linter for shell scripts that reports quoting mistakes, portability problems and common bugs, each with a numbered code.
Taught in
- Debugging: set -x, bash -n And Reading The Error — Bash Scripting & Command Line Automation