In the example below, an export
ed variable is re-set as local
in a function. Bash, Zsh, Fish don't pass on the original value to the child process. Are there any shells that make local
affect the local function body only, but pass the original export
ed value to the child process?
function the_func {
local MY_VAR="new value"
echo "=== $MY_VAR" # === prints "new value"
my -child -process # === gets MY_VAR="original"
}
export MY_VAR="original"
the_func
A subshell and readonly variables won't be good enough because the variables are also needed outside of the subshell. The args or name of the command could be in a variable that might class with the child process.