bash 或 zsh 中的“$-”是什么意思?
What does "$-" mean in bash or 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
这个值和系统有关系吗?
$-
当前选项集 shell。
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 , , … $N. The special parameter # is set to N.
The return status is always zero unless an invalid option is supplied.
$-
为您提供 shell 的当前选项集。
有关其他各种可用的特殊美元变量,请参阅此问题的已接受答案:
What are the special dollar sign shell variables?
因为你正在使用 zsh,运行 这个命令:
LESS=+/'PARAMETERS SET BY THE SHELL' man zshparam
查找:
- <S> Flags supplied to the shell on invocation or by the set or setopt commands.
对于bash(来自Docker),运行这个命令:
LESS=+/'^ *Special Parameters' man bash
阅读:
- Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i option).
今天我发现变量'$-'是一个随机字符串,但我不知道它代表什么。
➜ ~ 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
这个值和系统有关系吗?
$-
当前选项集 shell。
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 , , … $N. The special parameter # is set to N.
The return status is always zero unless an invalid option is supplied.
$-
为您提供 shell 的当前选项集。
有关其他各种可用的特殊美元变量,请参阅此问题的已接受答案:
What are the special dollar sign shell variables?
因为你正在使用 zsh,运行 这个命令:
LESS=+/'PARAMETERS SET BY THE SHELL' man zshparam
查找:
- <S> Flags supplied to the shell on invocation or by the set or setopt commands.
对于bash(来自Docker),运行这个命令:
LESS=+/'^ *Special Parameters' man bash
阅读:
- Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i option).