Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)

Liste des GroupesRevenir à cu shell 
Sujet : Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 13. Jan 2025, 03:54:02
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vm1v8a$2tk9v$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <vm0no6$17127$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
What (other, "better/cleaner") idioms were you thinking of?

In general, when I need to iterate over a set (in bash), I use "mapfile".

So, instead of:

    ... | while read ...

I will do:

    mapfile -t < <(...)
    for i in "${MAPFILE[@]}"; do
...
    done

I think more or less the same is available in ksh.

Oh, and another thing of interest to the original thread.  We were talking
about whether the real underlying problem in the "rm" command could or
should be fixed.  I did some reading and some testing.  "man rm" (on Linux)
does mention stdin being a terminal - implying, somewhat obliquely, that
the -i option checks that and behaves differently if stdin is not a
terminal.

However, the below does in fact remove the file (*), which suggests that the
implementation is not quite up to the man page:

    $ touch /tmp/foo
    $ echo y > /tmp/bar
    $ rm -iv /tmp/foo < /tmp/bar

(*) With the expected weird onscreen display/look.

--
Republican Congressman Matt Gaetz claims that only ugly women want
abortions, which they will never need since no one will impregnate them.

Date Sujet#  Auteur
11 Jan 25 * Problem with 'rm -i' in ksh21Janis Papanagnou
11 Jan 25 +* Re: Problem with 'rm -i' in ksh15Lem Novantotto
11 Jan 25 i`* Re: Problem with 'rm -i' in ksh14Janis Papanagnou
12 Jan 25 i `* Re: Problem with 'rm -i' in ksh13Lem Novantotto
12 Jan 25 i  `* Re: Problem with 'rm -i' in ksh12Janis Papanagnou
12 Jan 25 i   `* Re: Problem with 'rm -i' in ksh11Kenny McCormack
12 Jan 25 i    `* Re: Problem with 'rm -i' in ksh10Janis Papanagnou
12 Jan 25 i     +* Re: Problem with 'rm -i' in ksh2Janis Papanagnou
12 Jan 25 i     i`- Re: Problem with 'rm -i' in ksh1Lem Novantotto
13 Jan 25 i     `* Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)7Kenny McCormack
13 Jan 25 i      +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)1Janis Papanagnou
13 Jan 25 i      `* Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)5Lem Novantotto
13 Jan 25 i       +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)1Lem Novantotto
14 Jan 25 i       `* Re: Iterating over a set in bash3Keith Thompson
14 Jan 25 i        `* Re: Iterating over a set in bash2Lem Novantotto
14 Jan 25 i         `- Re: Iterating over a set in bash1Janis Papanagnou
11 Jan 25 `* Re: Problem with 'rm -i' in ksh5Christian Weisgerber
11 Jan 25  +* Re: Problem with 'rm -i' in ksh2Kenny McCormack
12 Jan 25  i`- Re: Problem with 'rm -i' in ksh1Janis Papanagnou
12 Jan 25  +- Re: Problem with 'rm -i' in ksh1Janis Papanagnou
12 Jan 25  `- Re: Problem with 'rm -i' in ksh1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal