bash 是否有办法在不取消设置的情况下取消导出变量?

Does bash have a way to un-export a variable without unsetting it?

是否可以 export Bash 中的一个变量,然后在不完全取消设置的情况下取消导出它? IE。让它对当前 shell 仍然可用,但对子进程不可用。

你总是可以这样做,但它很难看(我很好奇):

export FOO

#...

_FOO=$FOO
unset FOO
FOO=$_FOO

关于其他 shell 的回答也被接受。

export -n FOO

来自help export

Options:

  • -f refer to shell functions
  • -n remove the export property from each NAME
  • -p display a list of all exported variables and functions