help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do we get state of a flag in set -o ...


From: Chet Ramey
Subject: Re: How do we get state of a flag in set -o ...
Date: Wed, 12 Jul 2023 09:43:57 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 7/11/23 3:54 PM, Budi wrote:
EDIT:

How do we get state of a flag in set -o ... that has no directly alias
set [-+] , e.g.
set -o posix
or
set -o vi
?

not, e.g. set -o errexit , as it can be retrieved by echo $-

Two ways:

test -o optname

or

shopt -q -o optname

In each case, the return status is 0 if the option is enabled, 1 if it is not.

For example,

set -o posix
test -o posix && echo enabled
shopt -q -o posix && echo enabled

will echo `enabled' twice.

You can also check $SHELLOPTS, but the above two are easier.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]