我正在尝试掌握所有交互式/非交互式登录/非登录 shell 类型,并且我有一个小问题可以帮助我解答这个难题:
我理解,当你使用 SSH 登录到远程计算机时,你会获得一个登录 shell。如果我:
~$ logout
我断线了。
但是当我在桌面环境中打开终端时,我能得到登录 shell 吗?因为如果我尝试
~$ logout
bash: logout: not login shell: use 'exit'
那么有没有办法可以本地连接到登录 shell?
答案1
-ls
为了回答您发布的问题,是的,您可以通过传递选项 ie在 xterm 中运行登录 shell
xterm -ls
从man 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).
-l
您可以通过传递或--login
选项在现有终端中将 bash 作为登录 shell 启动
bash -l
这将启动登录 shell 作为当前 shell 的子 shell;如果你想代替当前交互式 shell 与登录 shell 关联,你可以使用exec
:
exec bash -l
或者,正如 Jos 所建议的你可以安装一个 SSH 服务器,然后像远程登录一样在本地登录
ssh localhost