默认情况下会xterm
启动一个交互式 shell。但是您也可以将其配置为启动交互式login-shell。
这意味着通过启动一个xterm
你会得到同一种 shell,就像通过 ssh/虚拟控制台/su 登录一样。
在 xterm 中配置login-shell的优点/缺点是什么?
我能想到:
uptime
,w
,last
等报告尽可能多的用户xterm
的开放。(优势?)bash
只有 source .login
, .profile
,/etc/profile.d
当作为login-shell启动时zsh
有类似的文件,它在作为login-shell启动时读取- 但在我的系统上,默认情况下它们是空的相关xterm
手册页部分:
Run Code Online (Sandbox Code Playgroud)-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).
还有一个资源:
Run Code Online (Sandbox Code Playgroud)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.”
在终端中运行登录 shell 将执行您放入的任何程序.profile
,即使您希望该程序每个会话仅运行一次(例如,ssh-agent
和其他密钥环)。运行登录 shell 将覆盖您在会话或终端的父进程中设置的环境变量。
在终端中运行登录 shell 的人遇到的最大问题是他们通常在登录 GUI 时不设置环境变量。这样做的缺点是环境变量因此只能在从终端启动的程序中可用,而不能从通过 GUI 直接启动的程序中使用。如果您确实在登录时设置了环境变量,那么在每个终端中再次设置它们充其量是毫无意义的,有时会出现如上所示的问题。
另见的.bashrc和.bash_profile文件之间的差异,替代的.bashrc,这将如果提问者有每个会话设置环境变量都可以避免我已经看到了堆叠交换了不少问题。