For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
set -u
myfunc() {
local a=
a=apple
echo "a is $a"
}
myfunc
Here's what I wanted or expected to see:
shellcheck currently says nothing about this. The issue is that the empty assignment local a= defeats the purpose of set -u, which won't be triggered on empty string.
If the developer really means empty string this can be written as local a='', otherwise local a is safer in that set -u is still effective against typos.
Other forms of assignment with modifiers are alias a=b / declare a=b / typeset a=b / export a=b / readonly a=b but I'm less sure that any of those are likely to appear with missing values.
For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
Here's what I wanted or expected to see:
shellcheck currently says nothing about this. The issue is that the empty assignment
local a=defeats the purpose ofset -u, which won't be triggered on empty string.If the developer really means empty string this can be written as
local a='', otherwiselocal ais safer in thatset -uis still effective against typos.Other forms of assignment with modifiers are
alias a=b/declare a=b/typeset a=b/export a=b/readonly a=bbut I'm less sure that any of those are likely to appear with missing values.