bash 在 Red Hat 5 中为“ROOT”设置 PATH

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4252041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 22:57:55  来源:igfitidea点击:

Setting PATH for 'ROOT' in Red Hat 5

bashpathredhat

提问by user353829

I have edited '/etc/profile' and added the following:

我编辑了“/etc/profile”并添加了以下内容:

export JAVA_HOME=/usr/java/jdk1.6.0_21

导出 JAVA_HOME=/usr/java/jdk1.6.0_21

However, when logged in as 'root': '# echo $JAVA_HOME' lists a different path.

但是,当以“root”身份登录时:“#echo $JAVA_HOME”会列出不同的路径。

How do I configure 'root' to pick the above path?

如何配置“root”以选择上述路径?

NB: Exporting paths in 'bashrc' or '.bash_profile', for root, did not work for account 'root'.

注意:导出“bashrc”或“.bash_profile”中的路径,对于 root,对帐户“root”不起作用。

采纳答案by Jonathan Leffler

There are only a limited number of places where the value can be mis-set for root. The home directory for the superuser is /root, so you should first look in /root/.bashrcand /root/.bash_profile. You might need to look in /etc/bashrc, too.

只有有限数量的地方可以为 root 设置错误的值。超级用户的主目录是/root,因此您应该首先查看/root/.bashrc/root/.bash_profile。你可能也需要进去看看/etc/bashrc

If none of that yields enlightenment, you could try debugging where the environment is set by adding set -x(and perhaps env) to the top of /etc/profile, maybe only if the person running it is root(so as not to disturb other users), and track what is executed and set. Use the envcommand to diagnose whether JAVA_HOME is already set on entry to /etc/profile.

如果这些都没有产生启发,您可以尝试通过添加set -x(并且可能env)到 的顶部来调试环境设置的位置/etc/profile,也许只有在运行它的人是root(以免打扰其他用户)时,并跟踪执行的内容并设置。使用该env命令来诊断 JAVA_HOME 是否已经在入口设置为/etc/profile.

The Bash manual (4.0 edition) says:

Bash 手册(4.0 版)说:

§6.2 Bash Startup Files

[...]

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the ‘--login' option, it first reads and executes commands from the file ‘/etc/profile', if that file exists. After reading that file, it looks for ‘~/.bash_profile', ‘~/.bash_login', and ‘~/.profile', in that order, and reads and executes commands from the first one that exists and is readable.

§6.2 Bash 启动文件

[...]

当 Bash 作为交互式登录 shell 或作为带有 '--login' 选项的非交互式 shell 调用时,它首先从文件“ /etc/profile”读取并执行命令(如果该文件存在)。读取该文件后,它会按该顺序查找“ ~/.bash_profile”、“ ~/.bash_login”和“ ~/.profile”,并从第一个存在且可读的命令开始读取并执行命令。

Unless you have done something unusual, root's ~is /root.

除非你做了一些不寻常的事情,否则 root~/root.