如何找到启动文件读取和Ubuntu启动图形界面时创建的环境变量

在Ubuntu 16.04中使用LXDE或Gnome,

  • 如何找到使用图形界面启动Ubuntu时创建的环境变量?

  • 当Ubuntu启动图形界面,读取和执行哪些启动文件时, /etc/profile/etc/profile /etc/profile.d/* ~/.profile~/.profile~/.bash_profile/etc/environment/etc/bash.bashrc~/.bashrc

谢谢。

这非常复杂。

Pam还可以添加环境变量,以及其他东西( login程序, getty ,等等……)。

我以前做的是添加样式的线条(见这个 )

 export CALLED_IN_ETC_PROFILE=$(date date +%s.%N) 

在所有可疑文件中,然后使用https://askubuntu.com/a/356973/16395查看结果。

要查找哪个程序/文件可以负责变量的设置,您可以尝试将shell的进程树查看到终端模拟器中:

 [romano:/etc/X11/Xsession.d] % pstree -a -s -l -p -u $$ systemd,1 splash └─gdm3,1926 └─gdm-session-wor,3752 └─gdm-x-session,3807,romano --run-script gnome-session --session=gnome └─upstart,3824 --user └─gnome-terminal-,5027 └─zsh,11224 └─pstree,11831 -a -s -l -p -u 11224 

…我认为 ,要启动图形会话, gdm-x-session是在非交互模式下从用户shell启动的(注意链中的UID更改),以便读取.profile (但不是.bashrc ,这是由终端仿真器中的shell读取的)。

如果从gnome-shell调用,树有些不同:

 bash-4.3$ pstree -a -s -l -p -u $$ systemd,1 splash └─gdm3,1926 └─gdm-session-wor,3752 └─gdm-x-session,3807,romano --run-script gnome-session --session=gnome └─upstart,3824 --user └─gnome-session-b,4162 --session=gnome └─gnome-shell,4278 └─xterm,11882 -e bash --noprofile --norc └─bash,11884 --noprofile --norc └─pstree,11885 -a -s -l -p -u 11884 

但这是预料之中的。

顺便说一句,在UID更改为用户之前,也可以设置很多环境变量; /etc/X11/Xsession.d中有很多脚本,并且可以设置环境变量的X服务器gdm (或者你使用的任何显示管理器)。