.profile文件是不是失效的?
Tofloor
poster avatar
lotuso
deepin
2020-09-14 05:39
Author
* 怀疑失效的原因有两点
  1. 在$HOME/.profile中配置的环境变量完全不起作用
  2. 根据图中框起来的来看,如果将可执行文件放在$HOME/.local/bin下应该也可以直接在终端中直接使用,但完全无效

将此软连接丢到/usr/local/bin下是可以正常使用的,如果按照.profile文件中的这个描述来说,应该放在图中位置效果是等同于放在/usr/local/bin下的,难道是我理解有误?



Reply Favorite View the author
All Replies
忘记、过去
deepin
2020-09-14 06:13
#1
linux系统里我记得说对于 .profile .bashrc /etc/profile ......这几个文件的加载和读取顺序有要求的。

一般终端默认使用 bash,那就修改 .bashrc 即可,修改保存后 source ~/.bashrc 生效。
Reply View the author
senluo
deepin
2020-09-14 06:15
#2
可以看下这个 bash环境变量设置 ,详细介绍了login 和 non-login这两个概念,在non-login下应该配置 $HOME/.bashrc
Reply View the author
neko
deepin
Ecological co-builder
Q&A Team
2020-09-14 06:24
#3
楼上正解
deepin图形桌面是 non-login 模式
Reply View the author
158******70
deepin
2020-11-27 00:29
#4

自己调查了一下,发现 .profile 失效的原因是 dde 并没有写配置加载这个文件。

一般来说, /etc/profile 与 $HOME/.profile 文件是会在 DM 登录时被加载的,这个加载的设置一般写在 Xsession 文件里面,举其他几个 DM 的例子:


gnome (gdm), 在 /etc/gdm3/Xsession下:

source_with_error_check () {
CONFIG_FILE="$1"
. "$CONFIG_FILE" 2>"$ERR"
if [ -s "$ERR" ]; then
. /etc/gdm3/config-error-dialog.sh
fi
cat "$ERR" >&2
truncate -s 0 "$ERR"
}

# First read /etc/profile and .profile
for file in /etc/profile "$HOME/.profile"; do
if [ -f "$file" ]; then
source_with_error_check "$file"
fi
done


kde (sddm), 在 /usr/share/sddm/scrīpts/Xsession 下:

case $SHELL in
*/bash)
[ -z "$BASH" ] && exec $SHELL $0 "$@"
set +o posix
[ -f /etc/profile ] && . /etc/profile
if [ -f $HOME/.bash_profile ]; then
. $HOME/.bash_profile
elif [ -f $HOME/.bash_login ]; then
. $HOME/.bash_login
elif [ -f $HOME/.profile ]; then
. $HOME/.profile
fiduiyu
;;


对于 dde (lightdm), profile 设置写在了 /etc/X11/Xsession.d/01deepin-profile 下:

[ -f /etc/profile ] && . /etc/profile


可以看到,DDE 登录时只会加载 /etc/profile,并不会加载 $HOME/.profile,因此打开 deepin-terminal 时,是拿不到 $HOME/.profile 的内容的。相对来说,开启 VS Code 时,VS Code 会用 login 模式自己维护一个 shell,因此在 VS Code 里启动的终端又可以拿到 $HOME/.profile 的内容了。


同为 lightdm 的 ubuntu 16.04 都会读取 $HOME/.profile 的内容,个人认为 DDE 选择不读取是有问题的……开发人员应该考虑一下这个问题?

Reply View the author
loaden
deepin
2021-01-10 21:40
#5
158******70

自己调查了一下,发现 .profile 失效的原因是 dde 并没有写配置加载这个文件。

一般来说, /etc/profile 与 $HOME/.profile 文件是会在 DM 登录时被加载的,这个加载的设置一般写在 Xsession 文件里面,举其他几个 DM 的例子:


gnome (gdm), 在 /etc/gdm3/Xsession下:

source_with_error_check () {
CONFIG_FILE="$1"
. "$CONFIG_FILE" 2>"$ERR"
if [ -s "$ERR" ]; then
. /etc/gdm3/config-error-dialog.sh
fi
cat "$ERR" >&2
truncate -s 0 "$ERR"
}

# First read /etc/profile and .profile
for file in /etc/profile "$HOME/.profile"; do
if [ -f "$file" ]; then
source_with_error_check "$file"
fi
done


kde (sddm), 在 /usr/share/sddm/scrīpts/Xsession 下:

case $SHELL in
*/bash)
[ -z "$BASH" ] && exec $SHELL $0 "$@"
set +o posix
[ -f /etc/profile ] && . /etc/profile
if [ -f $HOME/.bash_profile ]; then
. $HOME/.bash_profile
elif [ -f $HOME/.bash_login ]; then
. $HOME/.bash_login
elif [ -f $HOME/.profile ]; then
. $HOME/.profile
fiduiyu
;;


对于 dde (lightdm), profile 设置写在了 /etc/X11/Xsession.d/01deepin-profile 下:

[ -f /etc/profile ] && . /etc/profile


可以看到,DDE 登录时只会加载 /etc/profile,并不会加载 $HOME/.profile,因此打开 deepin-terminal 时,是拿不到 $HOME/.profile 的内容的。相对来说,开启 VS Code 时,VS Code 会用 login 模式自己维护一个 shell,因此在 VS Code 里启动的终端又可以拿到 $HOME/.profile 的内容了。


同为 lightdm 的 ubuntu 16.04 都会读取 $HOME/.profile 的内容,个人认为 DDE 选择不读取是有问题的……开发人员应该考虑一下这个问题?

这个是正解!

Reply View the author
thepoy
deepin
2021-01-17 06:16
#6

google搜了很多,只有deepin的.profile才不生效,真的莫名其妙,我还以为是我的问题

Reply View the author
xliang1015
deepin
2021-09-13 05:20
#7
158******70

自己调查了一下,发现 .profile 失效的原因是 dde 并没有写配置加载这个文件。

一般来说, /etc/profile 与 $HOME/.profile 文件是会在 DM 登录时被加载的,这个加载的设置一般写在 Xsession 文件里面,举其他几个 DM 的例子:


gnome (gdm), 在 /etc/gdm3/Xsession下:

source_with_error_check () {
CONFIG_FILE="$1"
. "$CONFIG_FILE" 2>"$ERR"
if [ -s "$ERR" ]; then
. /etc/gdm3/config-error-dialog.sh
fi
cat "$ERR" >&2
truncate -s 0 "$ERR"
}

# First read /etc/profile and .profile
for file in /etc/profile "$HOME/.profile"; do
if [ -f "$file" ]; then
source_with_error_check "$file"
fi
done


kde (sddm), 在 /usr/share/sddm/scrīpts/Xsession 下:

case $SHELL in
*/bash)
[ -z "$BASH" ] && exec $SHELL $0 "$@"
set +o posix
[ -f /etc/profile ] && . /etc/profile
if [ -f $HOME/.bash_profile ]; then
. $HOME/.bash_profile
elif [ -f $HOME/.bash_login ]; then
. $HOME/.bash_login
elif [ -f $HOME/.profile ]; then
. $HOME/.profile
fiduiyu
;;


对于 dde (lightdm), profile 设置写在了 /etc/X11/Xsession.d/01deepin-profile 下:

[ -f /etc/profile ] && . /etc/profile


可以看到,DDE 登录时只会加载 /etc/profile,并不会加载 $HOME/.profile,因此打开 deepin-terminal 时,是拿不到 $HOME/.profile 的内容的。相对来说,开启 VS Code 时,VS Code 会用 login 模式自己维护一个 shell,因此在 VS Code 里启动的终端又可以拿到 $HOME/.profile 的内容了。


同为 lightdm 的 ubuntu 16.04 都会读取 $HOME/.profile 的内容,个人认为 DDE 选择不读取是有问题的……开发人员应该考虑一下这个问题?

Deepin系统,大多数是本地操作,还是偶尔会用SSH登录,习惯了将配置写到profile中。

对于 dde (lightdm), profile 设置写在了 /etc/X11/Xsession.d/01deepin-profile。
添加一行,完美解决该问题,刚开始还以为自己哪儿配置问题。 [ -f $HOME/.profile ] && . $HOME/.profile
Reply View the author
hgyxbll
deepin
2021-10-14 05:49
#8

官方可以修正这个问题吗,或者在wiki中说明

Reply View the author