You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer, I would like shellcheck to warn me when my scripts declare variables that are not local scope, so that I can catch subtle errors more quickly, rather than having scripts blow up in production.
Bash and bash-like shells provide syntax for declaring that a variable is locally scoped, rather than globally scoped. In general, it is a good idea to prefer local scope, to prevent colliding with variables that influence how different commands run (think VERBOSE, LIBS, etc). Note that some shells such as POSIX sh, unfortunately do not provide syntax to declare locally scoped variables, and so only scripts with the relevant shebangs / filename patterns should receive this rule.
Note that some variables are expected to be global or even environment scope (PATH, USER, CC). Such variables should not be locally scoped.
The text was updated successfully, but these errors were encountered:
I would suggest that ALL variables in ALLCAPS be excluded from this check. I would also suggest that this functionality be controlled with a command line switch and the default would be OFF, unless the command line switch is present.
For new checks and feature suggestions
As a developer, I would like shellcheck to warn me when my scripts declare variables that are not local scope, so that I can catch subtle errors more quickly, rather than having scripts blow up in production.
Bash and bash-like shells provide syntax for declaring that a variable is locally scoped, rather than globally scoped. In general, it is a good idea to prefer local scope, to prevent colliding with variables that influence how different commands run (think
VERBOSE
,LIBS
, etc). Note that some shells such as POSIX sh, unfortunately do not provide syntax to declare locally scoped variables, and so only scripts with the relevant shebangs / filename patterns should receive this rule.Note that some variables are expected to be global or even environment scope (
PATH
,USER
,CC
). Such variables should not be locally scoped.The text was updated successfully, but these errors were encountered: