我了解交互式 shell 和非交互式 shell 之间的基本区别。但是,登录 shell 与非登录 shell 的确切区别是什么?
你能举例说明非登录交互式shell 的使用吗?
是~/.bashrc
唯一指定用户特定环境变量、别名、PATH
变量修改等的地方吗?
我问是因为这似乎~/.bashrc
是bash
-only,但其他 shell 也存在......
作为 Linux 用户,我一直只使用 bash,因为它是我使用的每个发行版的默认设置。使用其他 Unix 系统(如 BSD)的人似乎更频繁地使用其他 shell。为了多学习一点,我决定尝试一下 zsh。
作为 bash 用户:
我正在使用带有 bash shell 的全新安装的 ubuntu 16.04。我想做两件事:
jk
我在另一篇文章中读到如何做到这一点zsh
,我该怎么做bash
?
tl;博士
把bind '"jk":vi-movement-mode'
到您的.bashrc
文件后,set -o vi
:)
server@thinkpad:~$ tail -n 2 .bashrc
set -o vi
bind '"jk":vi-movement-mode'
Run Code Online (Sandbox Code Playgroud)
请参阅@grochmal 的回答以获得更详细的解释
zsh
当我bash
在 Windows 上启动时,我刚刚找到了一种启动方式
https://www.howtogeek.com/258518/how-to-use-zsh-or-another-shell-in-windows-10/。
建议在.bashrc
.
# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi
Run Code Online (Sandbox Code Playgroud)
什么[ -t 1 ]
意思?
这是真的吗?
那么,我可以这样做吗?
exec zsh
Run Code Online (Sandbox Code Playgroud) 我刚刚完成了OverTheWire Bandit 兵棋推演,等级 18。
那是一个惊喜。以下是此级别的说明。
下一级的密码存储在主目录的自述文件中。不幸的是,当您使用 SSH 登录时,有人修改了.bashrc以将您注销。
我在想一种让 shell 跳过 sourcing 的方法.bashrc
。但在我找到解决方案之前,我很想简单地启动与服务器的 SFTP 连接。我没想到它会起作用。但它做到了。我想知道为什么。我认为 SFTP 通过 SSH 运行。
为清楚起见,当我通过 SSH 连接到服务器时,正如预期的那样,我被踢了出去。
我的设置是:
我似乎无法设置自己的环境变量并在 X 会话启动时获取它。这是我尝试过的:
~/.bash_profile
在我以前的操作系统上工作,但我从这个答案中了解到它不是源自 Debian 中的 X 启动,而是衍生品mv .bash_profile .profile
按照建议做了,但它也不起作用,因为正如我后来从这里了解到的,~/.profile
当显示管理器启动 X 会话时不是来源~/.xsessionrc
. 这也不起作用,因为正如我从这里了解到的,它仅来自/etc/X11/Xsession
LightDM 不执行的源~/.xprofile
文件,但这也不起作用。尝试来自最后一个网站的建议,我~/.xinitrc
是这样的:
export QT_STYLE_OVERRIDE=GTK+
[ -f ~/.xprofile ] && source ~/.xprofile
~/.screenlayout/default.sh
awesome
Run Code Online (Sandbox Code Playgroud)
而我~/.xprofile
是这样的:
[[ -f ~/.bashrc ]] && . ~/.bashrc
source /etc/bash_completion.d/virtualenvwrapper
export GDK_NATIVE_WINDOWS=1 …
Run Code Online (Sandbox Code Playgroud) 我正在运行 RHEL5。我将简单的别名命令添加到~/.bashrc
. 当我启动一个新终端时,没有任何反应,但source ~/.bashrc
可以正常工作,所以我知道语法是正确的。我还进行了修改/源代码测试~/.bash_profile
,但它也不会在终端启动时执行。 ~/.bash_login
并且~/.profile
在我的系统上不存在。
这是我的~/.bashrc
# .bashrc
# Source global definitions if [ -f /etc/bashrc ]; then
. /etc/bashrc fi
# User specific aliases and functions
alias hi=hello
Run Code Online (Sandbox Code Playgroud)
和我的~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
Run Code Online (Sandbox Code Playgroud) 我认为源自登录 shell 的 .bash_profile(或 .profile)中的任何内容都可以在交互式 shell 中使用。
我的目标是在登录 shell 或交互式 shell 中提供可用的函数列表。
我使用的是 Ubuntu 14.04.1,并且我不使用 .profile,而是使用 .bash_profile。(.profile 已重命名)
所以目前我所做的,我已将函数插入 .bash_profile 中,但是当打开交互式终端时,只有当我使用 .bash_profile 时,它们才不可用bash -l
。