[[ $- = *i* ]] 在 bash 中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31155381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 13:16:55  来源:igfitidea点击:

What does [[ $- = *i* ]] mean in bash?

bash

提问by Cyril ALFARO

I'm installing liquidpromptand in the documentation they ask you to add [[ $- = *i* ]] && source ~/liquidprompt/liquidpromptin your .bashrc.

我安装liquidprompt及文档中他们要求你添加[[ $- = *i* ]] && source ~/liquidprompt/liquidprompt在你的.bashrc

I am trying to understand the first part of the line but it's hard for a noob in bash like me. If anyone has a nice doc or the answer...

我试图理解该行的第一部分,但对于像我这样的 bash 菜鸟来说很难。如果有人有好的文档或答案...

回答by choroba

$-contains the current shell options.

$-包含当前的 shell 选项。

In [[ ... ]], the right hand side of a =is interpreted as a pattern if not quoted. Therefore, *i*means ipossibly preceded or followed by anything.

在 中[[ ... ]]=如果没有引用,a 的右侧将被解释为模式。因此,*i*意味着i可能在任何事物之前或之后。

In other words, it checks wheter the ioption is present, i.e. whether the current shell is interactive.

换句话说,它检查i选项是否存在,即当前shell 是否是交互式的。

回答by 123

It is checking whether the options for the shell $-contains an iin them. The iis for interactive

它正在检查 shell 的选项中是否$-包含一个i。该i是互动

From the Bash man page:

Bash 手册页

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state.

交互式 shell 是在没有非选项参数和 -c 选项的情况下启动的,其标准输入和错误都连接到终端(由 isatty(3) 确定),或者是使用 -i 选项启动的。PS1 已设置,如果 bash 是交互式的,则 $- 包括 i,允许 shell 脚本或启动文件来测试此状态。

Also relevant

也相关