/ etc/profile中的Bash语法

spa*_*c24 6 unix linux bash profile sh

我只是注意到了这条线/etc/profile,我想知道这是什么意思,什么时候是真的.

if [ "${-#*i}" != "$-" ]; then
Run Code Online (Sandbox Code Playgroud)

i迭代几个*.sh文件.

很抱歉,如果这是一个愚蠢的问题,但你可以想象,在Google中寻找大多数符号实际上不是一个选择.

谢谢!

Eta*_*ner 7

OPTIONS联机帮助页的部分:

-i        If the -i option is present, the shell is interactive.
Run Code Online (Sandbox Code Playgroud)

Special Parameters联机帮助页的部分:

  -      Expands  to  the  current option flags as specified upon invoca-
         tion, by the set builtin command, or  those  set  by  the  shell
         itself (such as the -i option).
Run Code Online (Sandbox Code Playgroud)

Parameter Expansion联机帮助页的部分:

  ${parameter#word}
  ${parameter##word}
Run Code Online (Sandbox Code Playgroud)

这个词被扩展为产生一个模式,就像路径名扩展一样.如果模式匹配参数值的开头,那么扩展的结果是具有最短匹配模式(''''情况)或最长匹配模式(''##'的参数的扩展值'案例)删除.如果参数是@或*,则模式删除操作依次应用于每个位置参数,并且扩展是结果列表.如果参数是使用@或*下标的数组变量,则模式删除操作依次应用于数组的每个成员,并且扩展是结果列表.

所以"${-#*i}"说扩展$-变量并从字符串的开头删除直到字母i.然后!=将该扩展与扩展$-(相同的变量仅未修改)进行比较.

当它们不相同时,它意味着第一个扩展删除了一些内容,这意味着字母i出现在值中,$-这意味着(因为-i不是参数set)-i参数被传递给shell而shell是一个交互式shell.