Score:0

Acquiring state of a flag in set -o

ca flag

How do we get state of a flag in set -o ... that has no direct alias set [-+] , e.g.

set -o posix

or

set -o vi

?

not, e.g. set -o errexit as its set [-+] e can be retrieved by

$ echo $-

then it'll be determined if letter e exists at the output string. Please help sincerely.

Score:2
hr flag

You can use set -o without an argument:

$ set -o
allexport       off
braceexpand     on
emacs           off
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              on
xtrace          off

or look at the SHELLOPTS variable:

$ echo "$SHELLOPTS"
braceexpand:hashall:histexpand:history:interactive-comments:monitor:vi
in flag
I looked at the manual, `set --help` doesn't include this information, but `man bash` does tell you, very tersely, that `-o` can be used on invocation of bash and that if "shopt_option is not supplied, the names and values of the shell options accepted by shopt are printed on the standard output.".
Score:1
cn flag

With bash:

if shopt -qpo posix; then
  echo "turned on";
else
  echo "turned off";
fi

See: help set and help shopt

Source: https://unix.stackexchange.com/a/269776/74329

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.