我想通过 C-shell 脚本取消设置所有环境变量。
使用 unsetenv *
命令,我可以使用命令行来完成此操作。
我们怎样才能让它在我们的脚本中工作呢?
当我运行脚本时,我遇到了未定义的标识符问题
。
最佳答案
来自tcsh(1)
:
unsetenv pattern
Removes all environment variables whose names match pattern.
`unsetenv *' thus removes all environment variables; this is a
bad idea. It is not an error for nothing to be unsetenved.
因此使用unsetenv *
应该可以工作。您的(可能是旧的)(t)csh 版本可能不支持此功能?
无论哪种方式,正如手册页所说,取消设置一切可能是一个坏主意。您将需要保留各种变量,例如 HOME
、USER
和其他一些变量。更好的方法可能是这样的:
foreach e (`env`)
set name = `echo "$e" | cut -d "=" -f 1`
# Note: this list should be longer.
if ( "$name" != "HOME" ) then
unsetenv "$name"
endif
end
关于linux - 取消设置 C-Shell 中的所有环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52922129/