localis only valid in functions.
local foo=bar echo "$foo"
foo=bar echo "$foo"
local can only be used in functions. In other contexts, it's an error.
It's possible to source files containing
local from a function context but not from any other context. This is not good practice, but in these cases you can ignore this error.
ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.