CentOS 6.6 中的 root 用户不显示 CLASSPATH 变量

CLASSPATH variables not showing up for root user in CentOS 6.6

我在 VmWare Player 上 运行ning CentOS 6.6。我添加了路径

export CLASSPATH=$CLASSPATH:<path/to/jars>

所需的 jar 文件到 。bash_profile 位于我的主文件夹中。

同时执行以下命令:

gvanjoic@localhost$ echo $CLASSPATH

它按预期显示类路径。但是,作为 root 用户,我需要 运行 执行一些任务。所以在 运行 执行以下命令时,输出与预期不同。

gvanjoic@localhost: su
Password:
root@localhost gvanjoic$ echo $CLASSPATH

输出

.

因此,我无法执行任务。我在这里可能做错了什么。帮助表示赞赏。

仅供参考,gvanjoic 不在 sudoers 列表中。

您的 主文件夹中的.bashrc 仅针对您的 用户执行。

因此,当以 root 身份登录时,它不会被执行,并且 root 得到 "clean" shell。如果它们对整个系统有效,而不仅仅是对您的用户有效,您可能希望将这些行放入 /etc/profile

也可以尝试 "su -",因为“-”表示当您更改用户时,应该导出 .bashrc

来自 "man su"

   -, -l, --login
       Provide an environment similar to what the user would expect had the user logged in directly.

       When - is used, it must be specified as the last su option. The other forms (-l and --login) do not have this
       restriction.