Showing 6 of 6 total issues
Can't follow non-constant source. Use a directive to specify location. Open
source "${SANDBIN_HOME}/scripts/lib/lang.lib.zsh"
- Read upRead up
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Tips depend on target shell and yours is unknown. Add a shebang. Open
#@IgnoreInspection AddShebangLine
- Read upRead up
- Exclude checks
Tips depend on target shell and yours is unknown. Add a shebang.
Problematic code:
echo "$RANDOM" # Does this work?
Correct code:
#!/bin/sh
echo "$RANDOM" # Unsupported in sh. Produces warning.
or
#!/bin/bash
echo "$RANDOM" # Supported in bash. No warnings.
Rationale:
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
).
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. Please either add a shebang or use -s
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "${SANDBIN_HOME}/scripts/sandbin/lib/sandbin.lib.zsh"
- Read upRead up
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Note that A && B || C is not if-then-else. C may run when A is true. Open
hash git >/dev/null 2>&1 && env git clone https://github.com/jeslopalo/sandbin.git $SANDBIN_HOME || {
- Read upRead up
- Exclude checks
Note that A && B || C is not if-then-else. C may run when A is true.
Problematic code:
[[ $dryrun ]] && echo "Would delete file" || rm file
Correct code:
if [[ $dryrun ]]
then
echo "Would delete file"
else
rm file
fi
Rationale:
It's common to use A && B
to run B
when A
is true, and A || C
to run C
when A
is false.
However, combining them into A && B || C
is not the same as if A then B else C
.
In this case, if A
is true but B
is false, C
will run.
For the code sample above, if the script was run with stdout closed for any reason (such as explicitly running script --dryrun >&-
), echo would fail and the file would be deleted, even though $dryrun
was set!
If an if
clause is used instead, this problem is avoided.
Exceptions
Ignore this warning when you actually do intend to run C when either A or B fails.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Can't follow non-constant source. Use a directive to specify location. Open
source "${SANDBIN_HOME}/scripts/lib/colors.lib.zsh"
- Read upRead up
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
ShellCheck only supports sh/bash/dash/ksh scripts. Sorry! Open
#!/bin/zsh
- Read upRead up
- Exclude checks
ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!
Problematic code:
#!/usr/bin/python
print "Hello"
Rationale:
You have specified the shebang of an unsupported language or shell dialect.
ShellCheck only supports a limited number of Bourne-based Unix shells: bash, ksh, dash and POSIX sh.
It does not support scripts written for other shells like Zsh, Csh, Tcsh or PowerShell, and it does not support other scripting languages like PHP, Python, JavaScript or SQL.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.