我想通过C-shell脚本取消设置所有环境变量。
使用unsetenv *命令,我可以使用命令行来完成。
我们如何使其在脚本中起作用?
运行脚本时,我按下undefined identifier issue

最佳答案

来自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版本不支持此功能?

无论哪种方式,正如手册页上所述,取消所有设置可能不是一个好主意。您将需要保留各种变量,例如HOMEUSER和其他一些变量。更好的方法可能是:

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/

10-09 21:30