相关疑难解决方法(0)

登录 Shell 和非登录 Shell 的区别?

我了解交互式 shell 和非交互式 shell 之间的基本区别。但是,登录 shell 与非登录 shell 的确切区别是什么?

你能举例说明非登录交互式shell 的使用吗?

shell login

435
推荐指数
7
解决办法
25万
查看次数

是否有所有 shell 读取的“.bashrc”等效文件?

~/.bashrc 唯一指定用户特定环境变量、别名、PATH变量修改等的地方吗?

我问是因为这似乎~/.bashrcbash-only,但其他 shell 也存在......

bash environment-variables profile

126
推荐指数
4
解决办法
5万
查看次数

zsh 中有哪些功能而 bash 中缺少哪些功能,反之亦然?

作为 Linux 用户,我一直只使用 bash,因为它是我使用的每个发行版的默认设置。使用其他 Unix 系统(如 BSD)的人似乎更频繁地使用其他 shell。为了多学习一点,我决定尝试一下 zsh。

作为 bash 用户:

  • 我会错过哪些功能?
  • 我应该注意哪些?

bash zsh

63
推荐指数
4
解决办法
9392
查看次数

在 bash vi 模式下,映射 jk 退出插入模式

我正在使用带有 bash shell 的全新安装的 ubuntu 16.04。我想做两件事:

  1. 设置 vi 模式,以便我可以从终端进行类似 vim 的运动
  2. 通过键入退出插入模式 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 的回答以获得更详细的解释

bash keyboard-shortcuts vi

15
推荐指数
1
解决办法
6974
查看次数

[ -t 1 ] 检查什么?

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)

shell bash zsh test

15
推荐指数
3
解决办法
6718
查看次数

SFTP 在哪些方面不是基于 SSH?

我刚刚完成了OverTheWire Bandit 兵棋推演,等级 18

那是一个惊喜。以下是此级别的说明。

下一级的密码存储在主目录的自述文件中。不幸的是,当您使用 SSH 登录时,有人修改了.bashrc以将您注销。

我在想一种让 shell 跳过 sourcing 的方法.bashrc。但在我找到解决方案之前,我很想简单地启动与服务器的 SFTP 连接。我没想到它会起作用。但它做到了。我想知道为什么。我认为 SFTP 通过 SSH 运行。

为清楚起见,当我通过 SSH 连接到服务器时,正如预期的那样,我被踢了出去。

ssh sftp

9
推荐指数
2
解决办法
1719
查看次数

无法在 X 会话启动时导出环境变量

我的设置是:

  • Debian 测试 (stretch),最新
  • 启用自动登录的 LightDM
  • 很棒的窗口管理器
  • bash,在 ROXTerm 或 XTerm 中

我似乎无法设置自己的环境变量并在 X 会话启动时获取它。这是我尝试过的:

  • using~/.bash_profile在我以前的操作系统上工作,但我从这个答案中了解到它不是源自 Debian 中的 X 启动,而是衍生品
  • mv .bash_profile .profile按照建议做了,但它也不起作用,因为正如我后来从这里了解到的,~/.profile当显示管理器启动 X 会话时不是来源
  • 上述问题的答案建议使用~/.xsessionrc. 这也不起作用,因为正如我从这里了解到的,它仅来自/etc/X11/XsessionLightDM 不执行的源
  • Arch Linux wiki声称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)

bash debian environment-variables awesome lightdm

7
推荐指数
1
解决办法
5391
查看次数

.bashrc 和 .bash_profile 未执行

我正在运行 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)

bash rhel bashrc

4
推荐指数
1
解决办法
1万
查看次数

在交互式 shell 中找不到 ~/.bash_profile 中的函数

我认为源自登录 shell 的 .bash_profile(或 .profile)中的任何内容都可以在交互式 shell 中使用。

我的目标是在登录 shell 或交互式 shell 中提供可用的函数列表。

我使用的是 Ubuntu 14.04.1,并且我不使用 .profile,而是使用 .bash_profile。(.profile 已重命名)

所以目前我所做的,我已将函数插入 .bash_profile 中,但是当打开交互式终端时,只有当我使用 .bash_profile 时,它​​们才不可用bash -l

bash profile

2
推荐指数
1
解决办法
3005
查看次数