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: Dennis Williamson
Subject: Re: case statement with non-consecutive numbers
Date: Thu, 15 Apr 2021 16:58:51 -0500

On Thu, Apr 15, 2021, 4:48 PM Eli Schwartz <eschwartz@archlinux.org> wrote:

> On 4/15/21 5:22 PM, Dennis Williamson wrote:
> > On Thu, Apr 15, 2021, 4:17 PM <pauline-galea@gmx.com> wrote:
> >
> >>
> >> What other options could be available besides
> >>
> >> for ((i=1; i <= 1000; i++)); do
> >>
> >> Perhaps using $(seq 1 2 20)
> >>
> >> Anything else?
> >
> > Sequential c-style for loops. But that reduces maintainability due to
> > repetition of code.
> >
> > There's no reason to use seq unless you're writing for portability.
>
>
> That's a funny definition of portability, since seq isn't portable.
>
> It's not mandated by POSIX.
>
> It *will* be available on any system running the GNU coreutils, and
> FreeBSD/NetBSD do have it, so, depending on which systems you typically
> run, your scripts might work, but then one day you might try running
> your script on OpenBSD, which doesn't have it according to
> man.openbsd.org, and suddenly everything breaks.
>
> There are probably commercial vendors out there that don't have it
> either, but those are beyond my ability to trivially research.
>
> --
> Eli Schwartz
> Arch Linux Bug Wrangler and Trusted User
>

Perhaps I should have been more precise in my language. If one wants to
write a script portable across shells that may not have brace expansions on
systems that provide seq then seq is one of the available choices. There's
no doubt that statement could be further refined and precise even to the
point of including tables and references.

>


reply via email to

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