dash shell (unlike bash and busybox ash implementation where both examples print foo: ''
) takes value of previously
defined variable, i.e. guarding with local does not work:
$ foo=ee; bar() { local foo; echo "foo: '$foo'"; }; bar
foo: 'ee'
It requires declare it as empty:
$ foo=ee; bar() { local foo=; echo "foo: '$foo'"; }; bar
foo: ''
Is it a dash
bug (worth of reporting) or local
expect to initialize variable? The problem with local is that it's not POSIX, although there was an attempt (source which shows how different are local
implementations in various shells).
local
only means "the changes to this variable should not be seen outside of the current scope".local foo=$foo