help-bash
[Top][All Lists]
Advanced

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

Re: Using opt="on" versus opt=true


From: Greg Wooledge
Subject: Re: Using opt="on" versus opt=true
Date: Tue, 6 Apr 2021 20:49:29 -0400

On Wed, Apr 07, 2021 at 09:35:16AM +0900, Koichi Murase wrote:
> An interesting topic. I often use a modified version of this. I
> initialize `opt' with *an empty string* and then assign *1* when it is
> enabled.

That's cool, but if you have code that can disable an option, you
obviously have to remember to set it to the empty string rather than 0.
That asymmetry is a bit weird, and I would be worried about someone
failing to realize/remember that when maintaining the code.  But if it
works for you, then it works.

> For another way, when there are many options, I sometimes use what I
> call ``flags'' which is similar to the shell special variable $-.

>     case $arg in
>     (-o) flags+=f ;;
>     (-p) flags+=b ;;

Nifty.  I can see that being useful.

> When there are even more options, I use what I call ``opts'' which is
> similar to $SHELLOPTS and $BASHOPTS and is a colon-separated list of
> words. This can be tested by [[ :$opts: == *:word:* ]].

I don't care for this one.  An associative array would be cleaner,
and probably more efficient, unless you need bash 3.2 compatibility for
those Macs.



reply via email to

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