What does the output of echo $-1, echo $-2, echo $-3.. mean?

On one of my Linux boxes, it shows me:

echo $-1
echo $-2

And on another Linux box, it shows:

echo $-1
echo $-2

Are they mapping to some memory locations or some thing else?

  • 1
    The title is exhibiting the following problem in the sidebar: meta.stackexchange.com/q/229363/205964 – IQAndreas Oct 30 '14 at 4:58
  • I added a proposed edit which tried to fix it, but I soon realized that it's only the sidebar that renders the MathJax, which means that when the title is on this page, it just gets unnecessary backslashes. – IQAndreas Oct 30 '14 at 4:59

POSIX defined $- as:


(Hyphen.) Expands to the current option flags (the single-letter option names concatenated into a string) as specified on invocation, by the set special built-in command, or implicitly by the shell.

So $- can be different base on your shell or how you invoke it.

1 or 2 are separated token here. When the shell see unquote $, it will identify the start of any candidates for parameter expansion, command substitution, or arithmetic expansion. It saw $- and expanded it, left the rest unchanged.

You can see Token Recognition section for more details.

| improve this answer | |

echo $- prints options of the current shell (without - prefix). 1 and 2 are additional unrelated tokens.

| improve this answer | |

Adding on to Miroslav's answer:

echo $- prints options of the current shell (without - prefix). 1 and 2 are additional unrelated tokens.

This means that these are the options, for each machine respectively.


I have researched the meaning of each flag and compiled the meanings below, with minor paraphrasing.


If the -i option is present, the shell is interactive.


Monitor mode. Job control is enabled.


The shell performs brace expansion (see Brace Expansion). This is on by default.


If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.




Make bash act as if it had been invoked as a login shell



-H History Expansion

This feature is enabled by default for interactive shells.

| improve this answer | |

To expand on the existing answers, try echo "${-1}" and echo "${-2}" - you'll get a "Bad substitution" error because rather than using -1 as a variable name the hyphen is used to substitute a value if the variable name before it is undefined. For example:

$ unset foo
$ echo "${foo-bar}"
$ foo=test
$ echo "${foo-bar}"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.