Pattern: Overwriting PATH in shell script
Issue: -
PATH
is where the shell looks for the commands it executes. By inadvertently overwriting it, the shell will be unable to find commands (like cat
in this case).
You get this warning when ShellCheck suspects that you didn't meant to overwrite it (because it's a single path with no path separators).
Best shell scripting practice is to always use lowercase variable names to avoid accidentally overwriting exported and internal variables.
Example of incorrect code:
PATH=/some/dir
cat "$PATH/file"
Example of correct code:
Good practice: always use lowercase for unexported variables.
path=/some/dir
cat "$path/file"
Bad practice: use another uppercase name.
MYPATH=/some/dir
cat "$MYPATH/file"
If you're aware of the above and really do want to set your shell search path to /some/dir
, you can ignore this warning.