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

Re: bbc script



On Thu, Aug 19, 2021 at 08:56:22PM -0400, Greg Wooledge wrote:
> > On Thu, 19 Aug 2021, Greg Wooledge wrote:
> > > Also relevant: https://mywiki.wooledge.org/BashFAQ/115

Great explanation, Greg. I wish I had half of your talent :)

One small addendum: the "predefined strings" in the case statement
are actually patterns to match the (contents) of the variable in
question:

> The case statement simply compares what the user typed to a bunch of
> predefined strings.  You choose what those strings are.
> 
>       case $ch in
>         a) add; break;;
>         s) subtract; break;;
>         m) multiply; break;;
>         q) exit 0;;
>         *) echo "Unrecognized command.  Please try again.";;
>       esac

So the first one ("a") just matches when $ch contains exactly an "a".
But the last one ("*") matches everything (a way of saying "else",
or "if nothing matched, then...").

Same for the latter example:

>       case $ch in
>         a | ad | add) add; break;;

the "a | ad | add" is a pattern matching "a" or "ad", or "add". There
are more useful patterns.

Cheers
 - t

Attachment: signature.asc
Description: Digital signature


Reply to: