shellcheck
shellcheck copied to clipboard
SC2154 triggers only once, even among unrelated functions
For bugs
- Rule Id: SC2154
- My shellcheck version (
shellcheck --versionor 'online'): online - [x] 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
- [x] shellcheck.net (i.e. the latest commit) currently gives no useful warnings about this
- [x] 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 something {
echo "${a?}"
}
function unrelated {
echo "$a"
}
unrelated
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
[Line 8:](javascript:setPosition(8, 15))
echo "$a"
^-- [SC2154](https://www.shellcheck.net/wiki/SC2154) (warning): a is referenced but not assigned.
Using the ? expansion in one place means that the variable being used without assignment will not be caught in the other unrelated function.