[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: case statement with non-consecutive numbers
From: |
pauline-galea |
Subject: |
Re: case statement with non-consecutive numbers |
Date: |
Thu, 15 Apr 2021 22:09:12 +0200 |
I have a related question, if I could ask it. It is about the
'for' construct. What are the rules for constructing ranges
and individual numbers for loops that could be equivalent to
[1-5]|7|21-35)
Regards
> Sent: Friday, April 16, 2021 at 5:59 AM
> From: "Greg Wooledge" <greg@wooledge.org>
> To: help-bash@gnu.org
> Subject: Re: case statement with non-consecutive numbers
>
> On Thu, Apr 15, 2021 at 01:36:30PM -0400, Daniel Mills wrote:
> > On Thu, Apr 15, 2021 at 1:29 PM <pauline-galea@gmx.com> wrote:.
> >
> > >
> > > Doing more work on this, it looks like using commas also works
> > >
> > > case $k in
> > > [1-2,4-5,7]) printf "%-21s" $s ;;
> > > [3,6,8]) printf "%-21s\n" $s ;;
> > > esac
> > >
> > > Would that be correct?
> > >
> > >
> > >
> > >
> > The commas aren't needed, now if "$k" is a comma it will also match the
> > pattern. Simply [368] or [1-24-57] is what you want there
>
> And for the record, [1-2] and [12] are the same, so you can remove the
> hyphens as well. You need a range of at least 3 characters in a row
> for the hyphen to break even, and 4 for it to actually shorten the glob.
>
>
- case statement with non-consecutive numbers, pauline-galea, 2021/04/15
- Re: case statement with non-consecutive numbers, Greg Wooledge, 2021/04/15
- Re: case statement with non-consecutive numbers, pauline-galea, 2021/04/15
- Re: case statement with non-consecutive numbers, Daniel Mills, 2021/04/15
- Re: case statement with non-consecutive numbers, Greg Wooledge, 2021/04/15
- Re: case statement with non-consecutive numbers,
pauline-galea <=
- Re: case statement with non-consecutive numbers, Greg Wooledge, 2021/04/15
- Re: case statement with non-consecutive numbers, Greg Wooledge, 2021/04/15
- Re: case statement with non-consecutive numbers, Dennis Williamson, 2021/04/15
- Re: case statement with non-consecutive numbers, Greg Wooledge, 2021/04/15
- Re: case statement with non-consecutive numbers, Dennis Williamson, 2021/04/15
- Re: case statement with non-consecutive numbers, pauline-galea, 2021/04/15
- Re: case statement with non-consecutive numbers, Dennis Williamson, 2021/04/15
- Re: case statement with non-consecutive numbers, pauline-galea, 2021/04/15
- Re: case statement with non-consecutive numbers, Dennis Williamson, 2021/04/15
- Re: case statement with non-consecutive numbers, Eli Schwartz, 2021/04/15