linux - 如何获取我的 .profile 文件并使其更改当前 shell

标签 linux bash shell

我正在运行一个 init bash 脚本,在它结束时我想获取我的 .profile 脚本,而该脚本又会获取我的 .bashrc 文件。

出于某种原因,.profile 已获取(我可以判断,因为它打印出一条语句)但我的初始化脚本的其余部分未运行

我看过these两个questions两者都说要使用 source ~/.profile 这就是我正在做的(除了使用完整路径而不是 a)但它仍然无法正常工作。我做错了什么吗?

我的初始化脚本的结尾是这样的:

source "$USERDIR/.profile"
# This should be done from .profile but it is presently not working correctly
# Nothing below gets executed
source "$USERDIR/.bashrc"
cd $USERDIR

我做错了什么吗?

最佳答案

也许尝试执行:

source ~/.profile

作为 root 用户或使用 sudo

或者,您可以尝试在实际需要 sudo 的命令之前添加 sudo -E

Linux man page:

-E The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.

Linux and UNIX Man Pages:

The -E (preserve environment) option will override the env_reset option in sudoers(5). It is only available when either the matching command has the SETENV tag or the setenv option is set in sudoers(5).

关于linux - 如何获取我的 .profile 文件并使其更改当前 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38710079/

相关文章:

c++ - 树莓派无法接收信号,而在 ubuntu 机器上可以,Qt 程序

linux - 使用端口转发 SSH 连接到本地服务器?

regex - rsync --exclude-from 'list' 文件不工作

c++ - std::system 即使在父进程退出后也会执行吗?

linux - 基本 HTTP 身份验证 - 带 Cookie 的 wget

linux - 多节点连接管理

linux - 为什么这个 rsync 命令没有删除?

linux - bash: !": 在 Ubuntu 13.04 中未找到事件

linux - 将文件复制到子目录并重命名

linux - 如何添加 shell 脚本中包含的标志?