gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:48 26 4
gpt4 key购买 nike

我正在运行一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com