Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend local variables #1395

Open
2 tasks done
mcandre opened this issue Nov 20, 2018 · 2 comments
Open
2 tasks done

Recommend local variables #1395

mcandre opened this issue Nov 20, 2018 · 2 comments

Comments

@mcandre
Copy link
Contributor

mcandre commented Nov 20, 2018

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.

@matthewpersico
Copy link

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.

@mgedmin
Copy link

mgedmin commented May 3, 2019

Duplicate of #468?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants