invocation-option

Bash -n — syntax checking

Reads commands without executing them in noninteractive Bash. Use it to detect syntax errors, not to certify runtime correctness. The filename must be readable. Example prerequisite: create hello.sh as a readable text file containing a valid printf command.

Formal Syntax & Structure

bash syntaxbash
bash -n script.sh

Parameters & Attributes

NameTypeDescription
script.shpathPath of the script to parse.

Return Value

exit status

0 for successfully parsed ordinary script; nonzero for syntax errors or invocation/read failures.

Working Example

Example Snippetbash
bash -n hello.sh
Bash Reference