bash - "$-"在 bash 或 zsh 中意味着什么?

标签 bash zsh

<分区>

今天我发现变量'$-'是一个随机字符串,但我不知道它代表什么。

➜  ~ echo $-
569JNRTXZghikms

而且我无法更改值:

➜  ~ -='sss'
zsh: command not found: -=sss
➜  ~ 

并且,在 docker 中它是:

➜  ~ docker  run --rm -ti ubuntu          
root@7084255fd54e:/# echo $-
himBH

或者:

➜  ~ docker  run --rm -ti alpine ash
/ # echo $-
smi

它的值(value)与系统有关吗?

最佳答案

$- 为 shell 设置的当前选项。

来自 the Bash Reference Manual :

Using ‘+’ rather than ‘-’ causes these options to be turned off. The options can also be used upon invocation of the shell. The current set of options may be found in $-.

The remaining N arguments are positional parameters and are assigned, in order, to $1, $2, … $N. The special parameter # is set to N.

The return status is always zero unless an invalid option is supplied.

关于bash - "$-"在 bash 或 zsh 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37428556/

相关文章:

zsh - 使用通配符扩展来回显 zsh 中的所有变量

vim Vundle 的 PluginInstall 与 Archlinux 中的fish 冲突

linux - 运行 bash 脚本以从另一个目录关闭 tomcat

bash:使用 virtualenv 时出现意外标记 `(' 附近的语法错误

arrays - Bash:循环遍历字符串数组后无法读出带空格的字符串

linux - 自定义 zsh 自动完成

linux - zsh 下划线常用补全前缀

string - Bash:从变量 B 中删除变量 A 中的一系列字符串?

java - 命令行参数有空格的问题

linux - 如何使用 linux shell 创建包含重复值列表的文件?