shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Need to report on un-set environment variables

Open wardmw opened this issue 5 months ago • 2 comments

For bugs with existing features

Not an existing bug that I can find.

Here's a snippet or screenshot that shows the problem:

#!/usr/bin/env bash
${LS}

Here's what shellcheck currently says:

$ shellcheck ./shell-test.sh $

Here's what I wanted or expected to see:

$ shellcheck ./shell-test.sh ${LS} ^-^ SC9999 (warning): LS is undefined and used as a command. Verify that this is the intention. $

wardmw avatar Jul 29 '25 09:07 wardmw

That's intended behaviour.

Variables with only capital letters are considered to be externally defined. Use normal lowercase variables if you want them to be checked.

grische avatar Aug 05 '25 10:08 grische

Maybe activate the optional check for unassigned uppercase vars?

name:    check-unassigned-uppercase
desc:    Warn when uppercase variables are unassigned
example: echo $VAR
fix:     VAR=hello; echo $VAR
brother ~$ shellcheck -o check-unassigned-uppercase test.sh

In test.sh line 2:
${LS}
^---^ SC2154 (warning): LS is referenced but not assigned.

For more information:
  https://www.shellcheck.net/wiki/SC2154 -- LS is referenced but not assigned.

brother avatar Aug 07 '25 13:08 brother