sudo 有不同的环境,为什么?
我意识到:
sudo -i
env
不同于:
sudo -i
sudo env
它们都是 sudo,为什么它们不同?
就我而言,我意识到 PATH 非常不同,因此有时无法使用“sudo blah”运行,但当我第一次登录 sudo,然后运行命令时它可以工作。 (就像我的其他问题# 4976658)
I realize that:
sudo -i
env
is different from:
sudo -i
sudo env
They are both sudo, why are they different?
In my case, I realize the PATHs are very different, so sometimes things can't run with "sudo blah" but it works when I first log into sudo, then run the command. (Like my other question #4976658)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存在预期的差异,例如
SUDO_USER
、SUDO_UID
和SUDO_GID
。然后是
PATH
。当您运行时,
您应该期待 root 的
PATH
,但是当您运行时,您应该期待默认的
PATH
。我想你会发现这是由于 Ubuntu 和 Fedora 都采用的“安全路径”选项造成的。
我同意这很烦人。关于此行为还有许多其他线索。 :-/
例如,请参阅此 stackoverflow 线程:
sudo 更改 PATH - 为什么?
There are expected differences, such as
SUDO_USER
,SUDO_UID
, andSUDO_GID
.And then there is
PATH
.When you run
you should expect root's
PATH
, but when you runyou should expect a default
PATH
.I think you will find that this is due to the "secure path" option, that both Ubuntu and Fedora have adopted.
I agree it's annoying. There are many other threads about this behavior. :-/
For example, see this stackoverflow thread:
sudo changes PATH - why?