3

Today I found that variable '$-' is a random string, but I don't know what it stands for.

➜  ~ echo $-
569JNRTXZghikms

And I can't change the value:

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

And, in a docker it was:

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

Or:

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

Does it's value related to the system?

wrfly
  • 118
  • 1
  • 8
  • Explained with an example, http://tldp.org/LDP/abs/html/internal.html#EX34 – Inian May 25 '16 at 05:38
  • You can change what is reported by changing the shell options with `set`. – David C. Rankin May 25 '16 at 05:45
  • 1
    You have tagged the question `bash` but you are obviously using `zsh`. Docker is using `bash`, and that's why the string is different. Please edit the tags to the correct value. –  May 25 '16 at 05:48
  • Thank you all. Now I got it. – wrfly May 25 '16 at 06:17
  • @JonathanLeffler This question is asking about zsh. I do not believe that it is an exact duplicate of the one you linked. –  May 25 '16 at 07:51

3 Answers3

1

$- current options set for the shell.

From 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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Cloud
  • 18,753
  • 15
  • 79
  • 153
0

$- gives you the current options set for the shell.

See the accepted answer from this question for the various other special dollar variables available:

What are the special dollar sign shell variables?

Community
  • 1
  • 1
Jon
  • 10,678
  • 2
  • 36
  • 48
0

As you are using zsh, run this command:

LESS=+/'PARAMETERS SET BY THE SHELL' man zshparam

to find:

- <S> Flags supplied to the shell on invocation or by the set or setopt commands.


For bash (from Docker), run this command:

LESS=+/'^ *Special Parameters' man bash

To read:

- 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).