Shellcheck does not issue unused variable error when local variable shadows global
Author: dhouckCreated Sep 26, 2026Updated Sep 26, 2026
For bugs
- Rule Id (if any, e.g. SC1000):
- My shellcheck version (
shellcheck --versionor 'online'): online - I tried on shellcheck.net and verified that this is still a problem on the latest commit
- It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
For new checks and feature suggestions
- shellcheck.net (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
function func
{
local var=inner
}
var=outer
func
echo $varHere's what shellcheck currently says:
No issues detected
Here's what I wanted or expected to see:
the local var=inner line has no effect; it should generate an SC2034 or similar. Shellcheck sees var is read in the outer scope, but doesnʼt notice that the one inside func isnʼt talking about the same variable.
Source: koalaman/shellcheck