今天我发现变量'$-'是一个随机字符串,但我不知道它代表什么。
➜ ~ 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.