Zsh 是否有等同于 Bash 的 "local +x MY_VAR"?
Does Zsh have an equivalent to Bash's "local +x MY_VAR"?
在Bash中,以下函数将导出的ENV变量传递给子进程,同时还声明了一个局部变量w/the同名。 Zsh 中有等效项吗?
我不想使用 subshells
和 read-only variables
。目标是避免意外覆盖子进程使用的变量。我不知道子进程中使用了哪些 ENV 变量,或者哪些是调用进程中预先存在的变量。
在 Zsh 中,local +x
与 Bash 中的行为不同。 Zsh 似乎使用 local
或 local +x
取消设置变量。 (local +x
中的 +x
在 Zsh 中被忽略。) Bash 使用 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 中没有这样的等价物。
在Bash中,以下函数将导出的ENV变量传递给子进程,同时还声明了一个局部变量w/the同名。 Zsh 中有等效项吗?
我不想使用 subshells
和 read-only variables
。目标是避免意外覆盖子进程使用的变量。我不知道子进程中使用了哪些 ENV 变量,或者哪些是调用进程中预先存在的变量。
在 Zsh 中,local +x
与 Bash 中的行为不同。 Zsh 似乎使用 local
或 local +x
取消设置变量。 (local +x
中的 +x
在 Zsh 中被忽略。) Bash 使用 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 中没有这样的等价物。