deepin v20 beta不再加载~/.profile吗?
Tofloor
poster avatar
lindan
deepin
2020-04-20 23:20
Author
请教大家,用户环境变量在15.11版本中,可以配置在~/.profile文件中的,也一直正常使用。

v20 beta每次都必须手动执行source ~/.profile才能生效,重启或者打开新终端后,又会再次出现“未找到命令”!
Reply Favorite View the author
All Replies
avatar
lookfor
deepin
2020-04-20 23:47
#1
写到  ~/.bashrc 里
Reply View the author
avatar
stone
deepin
2020-04-21 01:02
#2
不是~/.xprofile 么?
~/.bashrc
~/.xinitrc
~/.xprofile
Reply View the author
avatar
luzhishen
deepin
2020-04-21 01:07
#3
https://bbs.deepin.org/post/192373
写到  ~/.bashrc 里

我胆小,习惯写在这里
Reply View the author
avatar
Vimvi2233
deepin
2020-04-21 01:22
#4
It has been deleted!
avatar
Feng Yu
deepin
2020-04-21 01:32
#5
你没理解shell加载配置文件的顺序和优先级,新手强烈建议先看懂此图:https://shreevatsa.wordpress.com ... r-bashrc-zshrc-etc/

百度到的资料是个有九个根本就是错的,看到那些一本正经的教用户去改/etc/profile的文章我就想骂,完全误人子弟,而且根本不验证,TMD全是百度过来的,还TMD全是来自于博客园和CSDN,尼玛绝了(可想而知博客园和CSDN的质量有多烂,百度权重还高的一批,一百度全是这俩网站排前面,反正我现在是对于博客园和CSDN的文章我是一个字都不信)
Reply View the author
Comments
archlte
2020-04-21 02:08
我很赞同
avatar
jerry979
deepin
2020-04-21 16:51
#6
https://bbs.deepin.org/post/192373
你没理解shell加载配置文件的顺序和优先级,新手强烈建议先看懂此图:https://shreevatsa.wordpress.com/20 ...

为啥改/etc/profile不对啊,求教
Reply View the author
avatar
neko
deepin
Ecological co-builder
Q&A Team
2020-04-21 17:23
#7
https://bbs.deepin.org/post/192373
为啥改/etc/profile不对啊,求教

/etc/profile 作用于所有用户,不是不能用只是不适合这个应用场景
Reply View the author
avatar
jerry979
deepin
2020-04-21 18:04
#8
https://bbs.deepin.org/post/192373
/etc/profile 作用于所有用户,不是不能用只是不适合这个应用场景

噢噢,我只有一个用户,那写在/etc/profile也可以了,感谢。
Reply View the author
Comments
lbygljq
2020-06-17 18:26
非交互式shell被调用时,首先从文件/etc/profile中读取并执行命令。然后按该顺序查找〜/.bash_profile,〜/.bash_login和〜/.profile,
abcfy2
2020-04-21 18:13
错的,任何时候避免改/etc/profile
avatar
走钢丝
deepin
2020-05-03 00:27
#9
本帖最后由 lidanger 于 2020-5-2 16:31 编辑

~/.profile 似乎真的没有加载,里面系统定义的 PATH 环境变量用 echo $PATH 查看时没有 。我说最近有些快捷键怎么不起作用了。

我这边没定义 ~/.bash_profile 和 ~/.bash_login 啊。

Reply View the author
Comments
lbygljq
2020-06-17 18:22
20中不知道搞了什么,也没有文档解释。
avatar
lbygljq
deepin
2020-06-17 18:21
#10
https://bbs.deepin.org/post/192373
你没理解shell加载配置文件的顺序和优先级,新手强烈建议先看懂此图:https://shreevatsa.wordpress.com/20 ...

man中这样说的:
        当bash作为交互式登录shell或具有--login选项的非交互式shell被调用时,它首先从文件/etc/profile中读取并执行命令(如果该文件存在)。读取该文件后,它将按该顺序查找〜/.bash_profile,〜/.bash_login和〜/.profile,并从存在的且可读的第一个命令中读取并执行命令。

〜/.profile文件注释:如果存在〜/.bash_profile或〜/.bash_login,则bash不会读取此文件。
Reply View the author
avatar
Feng Yu
deepin
2020-06-17 23:58
#11
https://bbs.deepin.org/post/192373
man中这样说的:
        当bash作为交互式登录shell或具有--login选项的非交互式shell被调用时,它首先 ...

详细的就是man手册说的那样,总结的内容就是看我文章中老外画的流程图和表格对照。

也就是profile文件只是交互登录模式下会加载,通常是系统初次启动或新开pts登录终端的时候(新上来的ssh用户)。而在已经运行的系统和账户上开shell则是交互非登录模式,压根不加载Profile,这其实也正是很多人发现改了profile无论怎么关闭终端再重开都不起作用的原因,发现只有重启才会生效。所以百度根本就是误人子弟的。而stackoverflow的答案则不会教人去改profile
Reply View the author
avatar
yiqing
deepin
2020-06-18 19:32
#12
正常来讲不是用的lightdm登录吗,与bash无关,而且lightdm应该是会source ~/.profile的才对,或许你可以给这个文件改改名字,https://wiki.archlinux.org/index.php/LightDM#Environment_variables,可以看一下这个
Reply View the author
avatar
duanyao
deepin
2020-09-06 16:16
#13
https://bbs.deepin.org/post/192373
详细的就是man手册说的那样,总结的内容就是看我文章中老外画的流程图和表格对照。

也就是profile文件只 ...

不是,实际上的问题是 deepin 的 lightdm 的行为改变了:过去 lightdm 在用户登录时会依次加载 "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile" ,但现在的版本不会了( 至少  $HOME/.profile 不会加载,其它的没验证)。

deepin lion 仓库的 lightdm 1.21.6-1 中,加载 profile 的代码在 /usr/sbin/lightdm-session 中:


  1. # Load profile
  2. for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
  3.     if [ -f "$file" ]; then
  4.         source_with_error_check "$file"
  5.     fi
  6. done
Copy the Code


而 deepin apricot (V20) 的 lightdm 1.26.0.6-1+eagle 中,/usr/sbin/lightdm-session 是不存在的,这可能是它不加载 ~/.profile 的原因。

至于 Display Manager 是否应该默认加载 ~/.profile ,应该说有一定的争议,ubuntu 认为是,而 debian 有争议,debian 10 的 lightdm 不加载。deepin 可能过去是跟随 ubuntu 的行为,V20 又改成跟随 debian 10 的行为。

这是 ubuntu 和 debian 的相关 bug 和文档:

https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/794315
https://help.ubuntu.com/community/EnvironmentVariables
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636108
Reply View the author
avatar
duanyao
deepin
2020-09-06 16:46
#14
https://bbs.deepin.org/post/192373
正常来讲不是用的lightdm登录吗,与bash无关,而且lightdm应该是会source ~/.profile的才对,或许你可以给 ...

不同发行版的 lightdm 默认行为不一样,ubuntu 的会加载 ~/.profile ,但 debian 10 和 deepin V20 就不会。arch 可能是跟随 ubuntu 。参见我上个回复。
Reply View the author
avatar
duanyao
deepin
2020-09-07 00:16
#15
本帖最后由 duanyao 于 2020-9-6 16:30 编辑

解决办法一:安装 sddm ,替换掉 lightdm,删除 /etc/X11/Xsession.d/01deepin-profile:

  1. sudo apt install sddm
  2. sudo dpkg-reconfigure sddm  # 此处选择 sddm 。如果要改回 lightdm ,则是 sudo dpkg-reconfigure lightdm
  3. sudo rm /etc/X11/Xsession.d/01deepin-profile
Copy the Code


  重启机器。

注:删除  /etc/X11/Xsession.d/01deepin-profile 的原因是它在 ~/.profile 之后执行,又执行了一遍 /etc/profile ,会把 ~/.profile 中设置的 PATH 给覆盖掉。
Reply View the author
avatar
duanyao
deepin
2020-09-07 00:24
#16
本帖最后由 duanyao 于 2020-9-6 16:27 编辑

解决办法二:修改 lightdm ,删除 /etc/X11/Xsession.d/01deepin-profile:

   
  1. wget https://github.com/canonical/lightdm/blob/master/debian/lightdm-session  # 下载 deepin/debian 缺失的 lightdm-session 文件
  2. chmod +x lightdm-session
  3. sudo cp lightdm-session /usr/sbin/lightdm-session
  4. sudo dedit /etc/lightdm/lightdm.conf   # 找到 session-wrapper=lightdm-session 一行,去掉注释。
  5. sudo rm /etc/X11/Xsession.d/01deepin-profile
Copy the Code

    重启机器。

注:删除  /etc/X11/Xsession.d/01deepin-profile 的原因同上。

使用这个方法时,建议也对 ~/.profile 做个小修改:将 `if [ -n "$BASH_VERSION" ]` 改为 `if [ -n $BASH_VERSINFO ]`,因为 lightdm-session 会清除 BASH_VERSION ,使得检测不准确。详见: https://github.com/canonical/lightdm/issues/144
Reply View the author
avatar
duanyao
deepin
2020-09-07 00:56
#17
https://bbs.deepin.org/post/192373
详细的就是man手册说的那样,总结的内容就是看我文章中老外画的流程图和表格对照。

也就是profile文件只 ...

profile (包括 /etc/profile 和 ~/.profile )有它存在的意义,一是适用于多种 shell 而不仅是 bash;二是图形界面登录的时候,他们设置的环境变量会应用到几乎所有的用户进程,而不仅是应用到终端中启动的进程。
Reply View the author
avatar
Feng Yu
deepin
2020-09-07 01:10
#18
https://bbs.deepin.org/post/192373
profile (包括 /etc/profile 和 ~/.profile )有它存在的意义,一是适用于多种 shell 而不仅是 bash;二 ...

这些我知道。profile的作用是所有shell的交互式登录入口加载文件,所以要求最小化,理论上语法最好能兼容几乎所有常见的shell,而很多国内的资料,尤其是CSDN,喜欢教人把这个文件当bashrc去用,写一堆只有bash才支持的语法,我就特别气,完全误人子弟。

相比之下,国外的资料,尤其是stackoverflow要严谨的多,几乎不会有人教新手去改profile,那根本是错误的做法,很多人根本搞不清楚shell是怎么加载配置文件的
Reply View the author
avatar
thepoy
deepin
2021-01-17 06:26
#19
duanyao
https://bbs.deepin.org/post/192373
详细的就是man手册说的那样,总结的内容就是看我文章中老外画的流程图和表格对照。

也就是profile文件只 ...

不是,实际上的问题是 deepin 的 lightdm 的行为改变了:过去 lightdm 在用户登录时会依次加载 "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile" ,但现在的版本不会了( 至少  $HOME/.profile 不会加载,其它的没验证)。

deepin lion 仓库的 lightdm 1.21.6-1 中,加载 profile 的代码在 /usr/sbin/lightdm-session 中:


  1. # Load profile
  2. for file in "/etc/profile" "$HOME/.profile" "/etc/xprofile" "$HOME/.xprofile"; do
  3.     if [ -f "$file" ]; then
  4.         source_with_error_check "$file"
  5.     fi
  6. done
Copy the Code


而 deepin apricot (V20) 的 lightdm 1.26.0.6-1+eagle 中,/usr/sbin/lightdm-session 是不存在的,这可能是它不加载 ~/.profile 的原因。

至于 Display Manager 是否应该默认加载 ~/.profile ,应该说有一定的争议,ubuntu 认为是,而 debian 有争议,debian 10 的 lightdm 不加载。deepin 可能过去是跟随 ubuntu 的行为,V20 又改成跟随 debian 10 的行为。

这是 ubuntu 和 debian 的相关 bug 和文档:

https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/794315
https://help.ubuntu.com/community/EnvironmentVariables
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=636108

deepin20 .xprofile也不加载,请问现在如何添加全局环境变量呢?

Reply View the author
avatar
duanyao
deepin
2021-01-26 04:42
#20
thepoy

deepin20 .xprofile也不加载,请问现在如何添加全局环境变量呢?

按 16 楼修改系统。

Reply View the author