简体   繁体   中英

Does Zsh have an equivalent to Bash's “local +x MY_VAR”?

In Bash, the following function passes the exported ENV variable to the child process, while also declaring a local variable w/the same name. Is there an equivalent in Zsh?

I don't want to use subshells and read-only variables . The goal is to avoid accidentally overriding a variable the child process uses. I won't know which ENV variables are used in the child process or which are pre-existing from the calling process.

In Zsh, local +x , has different behaviour than the one in Bash. Zsh seems to unset the variable using local or local +x . ( +x in local +x is ignored in Zsh.) Bash passes on the original variable using local +x :

function the_func {
  local +x  MY_VAR="new value"
  my -child -process  # === in zsh:  $MY_VAR is undefined
                      # === in bash: $MY_VAR="original"
}

export MY_VAR="original"
the_func

不,ZSH中没有这样的等效项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM