默认情况下xterm
启动一个交互式 shell。但您也可以将其配置为启动交互式登录外壳。
这意味着启动后xterm
您将获得与通过 ssh/虚拟控制台/su 登录相同的 shell。
配置a的优点/缺点是什么登录外壳在 xterm 中?
我能想到:
uptime
、w
等last
报告与xterm
打开的用户一样多的用户。 (优势?)bash
仅来源.login
,.profile
,/etc/profile.d
开始时为登录外壳zsh
有类似的文件,启动时会读取这些文件登录外壳- 但在我的系统上它们默认是空的
相关xterm
手册页部分:
-ls This option indicates that the shell that is started in the xterm window will be a login shell (i.e., the first character of argv[0] will be a dash, indicating to the shell that it should read the user's .login or .profile).
还有一个资源:
loginShell (class LoginShell) Specifies whether or not the shell to be run in the window should be started as a login shell. The default is “false.”
答案1
在终端中运行登录 shell 将执行您放入的任何程序.profile
,即使您希望该程序每个会话仅运行一次(例如,ssh-agent
和其他密钥环)。运行登录 shell 将覆盖您在会话或终端父进程中设置的环境变量。
在终端中运行登录 shell 的人遇到的最大问题是,他们在登录 GUI 时通常不会设置环境变量。这样做的缺点是环境变量仅在从终端启动的程序中可用,而在通过 GUI 直接启动的程序中不可用。如果您确实在登录时设置了环境变量,那么在每个终端中再次设置它们充其量是毫无意义的,有时还会出现如上所示的问题。
也可以看看.bashrc 和 .bash_profile 之间的区别,.bashrc 的替代方案,以及我在 Stack Exchange 上看到的很多问题,如果提问者为每个会话设置了环境变量,这些问题就可以避免。