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.shellDate : 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 wantabortions, which they will never need since no one will impregnate them.