help-bash
[Top][All Lists]
Advanced

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

Re: case statement with non-consecutive numbers


From: Greg Wooledge
Subject: Re: case statement with non-consecutive numbers
Date: Thu, 15 Apr 2021 11:47:25 -0400

On Thu, Apr 15, 2021 at 05:39:10PM +0200, pauline-galea@gmx.com wrote:
> How can I deal with using a case statement with numbers which are not 
> consecutive,
> or with a sequence of ranges.  Looked for examples, but were not specific 
> enough
> about numerical values that are not consecutive.

So vague.

I'm going to assume you started with something like this:

case $input in
  [2-6]) echo "yeah, that's good";;
esac

and you maybe figured out how to extend it to something like this:

case $input in
  [2-68-9]) echo "yeah, that's good, screw 7";;
esac

but then you struggled with how to extend it to something like "3 to 5,
or 9 to 13" because you can't express that with a single glob-type
pattern.

Fear not!  You can just use more than one pattern.

case $input in
  [3-5]|9|1[0-3]) echo "yeah, that's good";;
esac



reply via email to

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