Deutsch   English   Français   Italiano  
<vm1v8a$2tk9v$1@news.xmission.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
Date: Mon, 13 Jan 2025 02:54:02 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vm1v8a$2tk9v$1@news.xmission.com>
References: <vlsqmt$fem4$1@dont-email.me> <vm0ela$15i9h$1@dont-email.me> <vm0inq$2st9j$1@news.xmission.com> <vm0no6$17127$1@dont-email.me>
Injection-Date: Mon, 13 Jan 2025 02:54:02 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
	logging-data="3068223"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Bytes: 2157
Lines: 38

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.