diff --git a/SC2148.md b/SC2148.md index 5bdff2c..1f5fc1f 100644 --- a/SC2148.md +++ b/SC2148.md @@ -1,20 +1,29 @@ -## Shebang (#!) missing. Assuming Bash. +## Tips depend on target shell and yours is unknown. Add a shebang. ### Problematic code: - echo "Hello World" + echo "$RANDOM" # Does this work ### Correct code: #!/bin/sh - echo "Hello World" + echo "$RANDOM" # Unsupported in sh. Produces warning. + +or + + #!/bin/bash + echo "$RANDOM" # Supported in bash. No warnings. ### Rationale: -ShellCheck warns about different things for different shells. It uses the shebang to determine which shell to warn for. For the command line client, this can be overridden with `-s`, e.g. `shellcheck -s sh file`. +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. -If you don't specify the shell type in any way, ShellCheck assumes a default and gives this message. +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`). + +Note that this error can not be ignored with a [[directive]]. It is not a suggestion to improve your script, but a warning that ShellCheck lacks information it needs to be helpful. ### Exceptions -None. Just specify the shell type, either in a shebang or as a cli flag. \ No newline at end of file +None. Please either add a shebang or use `-s`. \ No newline at end of file