是否使用登录 shell 运行 xterm?

max*_*zig 5 shell login xterm

默认情况下会xterm启动一个交互式 shell。但是您也可以将其配置为启动交互式login-shell

这意味着通过启动一个xterm你会得到同一种 shell,就像通过 ssh/虚拟控制台/su 登录一样。

在 xterm 中配置login-shell的优点/缺点是什么?

我能想到:

  • uptimewlast等报告尽可能多的用户xterm的开放。(优势?)
  • bash只有 source .login, .profile,/etc/profile.d当作为login-shell启动时
  • zsh有类似的文件,它在作为login-shell启动时读取- 但在我的系统上,默认情况下它们是空的

相关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).
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.”
Run Code Online (Sandbox Code Playgroud)

Gil*_*il' 5

在终端中运行登录 shell 将执行您放入的任何程序.profile,即使您希望该程序每个会话仅运行一次(例如,ssh-agent和其他密钥环)。运行登录 shell 将覆盖您在会话或终端的父进程中设置的环境变量。

在终端中运行登录 shell 的人遇到的最大问题是他们通常在登录 GUI 时不设置环境变量。这样做的缺点是环境变量因此只能在从终端启动的程序中可用,而不能从通过 GUI 直接启动的程序中使用。如果您确实在登录时设置了环境变量,那么在每个终端中再次设置它们充其量是毫无意义的,有时会出现如上所示的问题。

另见的.bashrc和.bash_profile文件之间的差异替代的.bashrc,这将如果提问者有每个会话设置环境变量都可以避免我已经看到了堆叠交换了不少问题。