AJP
AJP

Reputation: 28563

bash: Find the values from set

I can use the set command to change bash shell options, e.g.:

set -ex

Is there a command to check that the -e and -x options have been set?

Upvotes: 0

Views: 327

Answers (3)

clt60
clt60

Reputation: 63974

The $- in a short from, and you can check the $SHELLOPTS for a comma separated list of options.

echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi

set -x
echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi:xtrace
                                                                       ^^^^^^
set +x
set -v
echo $SHELLOPTS
braceexpand:hashall:histexpand:history:interactive-comments:monitor:verbose:vi
                                                                    ^^^^^^^

etc...

for the list, check: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html

Upvotes: 5

Barmar
Barmar

Reputation: 782693

The variable $- contains all the shell options:

  - Expands to the current option flags as specified upon invocation, 
    by the set builtin command, or those set by shell itself (such as 
    the -i option).

Upvotes: 2

Wojtek Surowka
Wojtek Surowka

Reputation: 21013

From man bash: "The current set of options may be found in $-", so use

echo $-

Upvotes: 2

Related Questions