shellcheck
shellcheck copied to clipboard
local variable declaration blocks a warning about unassigned global variable with the same name
For bugs
- Rule Id: SC2154
- My shellcheck version: 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:
#! /usr/bin/env bash
func1() {
echo "$myvar"
}
func2() {
local myvar=""
}
func1
func2
Here's what shellcheck currently says:
$ shellcheck myscript
No issues detected!
Here's what I wanted or expected to see:
$myvar in func1 is referenced but not assigned.
If executed using bash -u test.sh:
/tmp/test.sh: line 4: myvar: unbound variable
Same here.