Skip to content

Files

Latest commit

 

History

History
35 lines (22 loc) · 982 Bytes

SC2148.md

File metadata and controls

35 lines (22 loc) · 982 Bytes

Pattern: Missing target shell for Bash script

Issue: -

Description

Different shells support different features. To give effective advice, ShellCheck needs to know which shell your script is going to run on. You will get a different numbers of warnings about different things depending on your target shell.

ShellCheck normally determines your target shell from the shebang (having e.g. #!/bin/sh as the first line). The shell can also be specified from the CLI with -s, e.g. shellcheck -s sh file.

If you don't specify shebang nor -s, ShellCheck gives this message and proceeds with some default (bash).

Example of incorrect code:

echo "$RANDOM"   # Does this work?

Example of correct code:

#!/bin/sh
echo "$RANDOM"  # Unsupported in sh. Produces warning.

or

#!/bin/bash
echo "$RANDOM"  # Supported in bash. No warnings.

Further Reading