当我在sudo中使用任何命令时,环境变量就不存在了。例如,在设置HTTP_PROXY后,命令wget在没有sudo的情况下工作正常。但是如果我键入sudo wget,显示说不能绕过代理设置。
发布于 2018-08-02 14:17:24
首先你需要export HTTP_PROXY。其次,你需要仔细阅读man sudo,且注意-E标记。这样做是可行的:
$ export HTTP_PROXY=foof
$ sudo -E bash -c 'echo $HTTP_PROXY'下面是手册页的引文:
-E, --preserve-env
Indicates to the security policy that the user wishes to reserve their
existing environment variables. The security policy may eturn an error
if the user does not have permission to preserve the environment.https://stackoverflow.com/questions/-100005894
复制相似问题