Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What is green and lives in the ocean? A: Moby Pickle.


comp / comp.unix.shell / Re: Problem with 'rm -i' in ksh

SubjectAuthor
* Problem with 'rm -i' in kshJanis Papanagnou
+* Re: Problem with 'rm -i' in kshLem Novantotto
|`* Re: Problem with 'rm -i' in kshJanis Papanagnou
| `* Re: Problem with 'rm -i' in kshLem Novantotto
|  `* Re: Problem with 'rm -i' in kshJanis Papanagnou
|   `* Re: Problem with 'rm -i' in kshKenny McCormack
|    `* Re: Problem with 'rm -i' in kshJanis Papanagnou
|     +* Re: Problem with 'rm -i' in kshJanis Papanagnou
|     |`- Re: Problem with 'rm -i' in kshLem Novantotto
|     `* Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)Kenny McCormack
|      +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)Janis Papanagnou
|      `* Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)Lem Novantotto
|       +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)Lem Novantotto
|       `* Re: Iterating over a set in bashKeith Thompson
|        `* Re: Iterating over a set in bashLem Novantotto
|         `- Re: Iterating over a set in bashJanis Papanagnou
`* Re: Problem with 'rm -i' in kshChristian Weisgerber
 +* Re: Problem with 'rm -i' in kshKenny McCormack
 |`- Re: Problem with 'rm -i' in kshJanis Papanagnou
 +- Re: Problem with 'rm -i' in kshJanis Papanagnou
 `- Re: Problem with 'rm -i' in kshKeith Thompson

1
Subject: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 11 Jan 2025 04:05 UTC
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 05:05:48 +0100
Organization: A noiseless patient Spider
Lines: 69
Message-ID: <vlsqmt$fem4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 11 Jan 2025 05:05:50 +0100 (CET)
Injection-Info: dont-email.me; posting-host="084cea3a58bc5f6225d8f47497c4a4fc";
logging-data="506564"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LmNDuXi7+V2cbL4vV5j1x"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:RwsEEsWHGfawoDTINonr1p+imck=
X-Enigmail-Draft-Status: N1110
X-Mozilla-News-Host: news://news.eternal-september.org:119
View all headers

I came across an issue whose origin I could not track down, neither
by constructing a test sample from scratch nor by reducing the whole
shell program. So I'm asking here just generally whether the observed
effect triggers some memories of the audience to get any hint or some
ideas what might possibly be a source of the issue. The context is...

I'm populating a set of files in an associative array (defined with
'typeset -A a_set') using
a_set["${a_file}"]=
finally I want to remove them with 'rm'. So far so good. The program
creates (for example) for these commands the respective output[*]

printf "rm '%s'\n" "${!a_set[@]}"
=>
rm 'rmd2'
rm 'rmd4'
rm 'rmd9 2'
rm 'rmd9 3'

print "${!a_set[@]}"
=>
rmd2 rmd4 rmd9 2 rmd9 3

rm "${!a_set[@]}"
=>
# no output, and correctly removes the four sample files as expected

Since that's what I actually want I could just use that and be fine.

But being paranoid (with removing files) I wanted to use for a period
of time (to obtain confidence) the individual confirmations 'rm -i'

rm -i "${!a_set[@]}"
=>
rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?

The 'rm -i' version is just flushing out the above line on stderr
(and does nothing else)!

(I also tried '/bin/rm -i' to be on the safe side but to no avail.)

If the single shell commands (typeset -A, assignations, rm -i) are
issued interactively the 'mv -i' works as expected; I'm getting asked
for each file whether it shall be removed or not...

(1681)$ typeset -A a_set
(1682)$ a_set["rmd2"]=
(1683)$ a_set["rmd3"]=
(1684)$ a_set["rmd9 2"]=
(1685)$ a_set["rmd9 3"]=
(1686)$ print "${!a_set[@]}"
rmd2 rmd3 rmd9 2 rmd9 3
(1687)$ rm -i "${!a_set[@]}"
rm: remove regular file `rmd2'? n
rm: remove regular file `rmd3'? n
rm: remove regular file `rmd9 2'? n
rm: remove regular file `rmd9 3'? n

Does that effect - interaction of rm -i behavior with non-interactive
ksh, flushing the confirmation messages! - sound familiar to anybody?

(I get the same behavior with 'ksh 93u' and 'ksh 93u+m', BTW.)

Janis

[*] Note: in Kornshell the expression ${!a_set[@]} expands to the
list of keys/indexes of the associative array a_set.

Subject: Re: Problem with 'rm -i' in ksh
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 11 Jan 2025 11:06 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 11:06:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <vltjc3$htgh$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 11 Jan 2025 12:06:43 +0100 (CET)
Injection-Info: dont-email.me; posting-host="ae3d9ff2231833ddad4ddf3a2d69e45c";
logging-data="587281"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mKjPu4Pe1P6oFQ3zx7CnNPXdBJ2M9yqk="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:nQtinnxU8wgI0TlB4NxpSWKPG98=
View all headers

Il Sat, 11 Jan 2025 05:05:48 +0100, Janis Papanagnou ha scritto:

> Does that effect - interaction of rm -i behavior with non-interactive
> ksh, flushing the confirmation messages! - sound familiar to anybody?
>
> (I get the same behavior with 'ksh 93u' and 'ksh 93u+m', BTW.)

Uhmmm... here it works. But maybe I'm missing something...

>11:59:35<lem@biggy:/tmp/prova$ cat mioscript
#!/bin/ksh
unset f_names
typeset -A f_names
f_names["file1"]=
f_names["file2"]=
f_names["file3 3"]=
echo "${!f_names[@]}"
rm -i "${!f_names[@]}"
>11:59:43<lem@biggy:/tmp/prova$ ./mioscript
file1 file2 file3 3
rm: rimuovere file regolare vuoto 'file1'? n
rm: rimuovere file regolare vuoto 'file2'? n
rm: rimuovere file regolare vuoto 'file3 3'? n
>12:00:28<lem@biggy:/tmp/prova$ ksh ./mioscript
file1 file2 file3 3
rm: rimuovere file regolare vuoto 'file1'? n
rm: rimuovere file regolare vuoto 'file2'? n
rm: rimuovere file regolare vuoto 'file3 3'? n
>12:00:38<lem@biggy:/tmp/prova$ ksh --version
version sh (AT&T Research) 93u+m/1.0.8 2024-01-01
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 11 Jan 2025 14:07 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 15:07:05 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vlttua$la3m$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vltjc3$htgh$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 11 Jan 2025 15:07:06 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a1644839a0307c2f39264ce2a86c076e";
logging-data="698486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MpZJIQ/KHksQ6+/M/sawf"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:zTq650VCy2f36ixBoyEMfZkVH4c=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vltjc3$htgh$1@dont-email.me>
View all headers

On 11.01.2025 12:06, Lem Novantotto wrote:
> Il Sat, 11 Jan 2025 05:05:48 +0100, Janis Papanagnou ha scritto:
>
>> Does that effect - interaction of rm -i behavior with non-interactive
>> ksh, flushing the confirmation messages! - sound familiar to anybody?
>>
>> (I get the same behavior with 'ksh 93u' and 'ksh 93u+m', BTW.)
>
> Uhmmm... here it works. But maybe I'm missing something...

Yes, just these commands in a script work also in my environment.
(That was what I meant when I wrote: "constructing a test sample
from scratch"; it didn't lead me anywhere, since it just wasn't
reproducible in a primitive context like that.)

I think it must have to do with the shell environment that in
some way affects how 'rm -i' behaves. But I have no idea how an
external (shell-environment-)condition could look like that makes
an executed program like 'rm' behave as if all '-i' confirmations
are "magically" considered as being each answered by "no" (without
me typing anything).

Janis

>
>> 11:59:35<lem@biggy:/tmp/prova$ cat mioscript
> #!/bin/ksh
> unset f_names
> typeset -A f_names
> f_names["file1"]=
> f_names["file2"]=
> f_names["file3 3"]=
> echo "${!f_names[@]}"
> rm -i "${!f_names[@]}"
>> 11:59:43<lem@biggy:/tmp/prova$ ./mioscript
> file1 file2 file3 3
> rm: rimuovere file regolare vuoto 'file1'? n
> rm: rimuovere file regolare vuoto 'file2'? n
> rm: rimuovere file regolare vuoto 'file3 3'? n
>> 12:00:28<lem@biggy:/tmp/prova$ ksh ./mioscript
> file1 file2 file3 3
> rm: rimuovere file regolare vuoto 'file1'? n
> rm: rimuovere file regolare vuoto 'file2'? n
> rm: rimuovere file regolare vuoto 'file3 3'? n
>> 12:00:38<lem@biggy:/tmp/prova$ ksh --version
> version sh (AT&T Research) 93u+m/1.0.8 2024-01-01
>

Subject: Re: Problem with 'rm -i' in ksh
From: Christian Weisgerber
Newsgroups: comp.unix.shell
Date: Sat, 11 Jan 2025 14:01 UTC
References: 1
Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 14:01:34 -0000 (UTC)
Message-ID: <slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
References: <vlsqmt$fem4$1@dont-email.me>
Injection-Date: Sat, 11 Jan 2025 14:01:34 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="10471"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
View all headers

On 2025-01-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

> rm -i "${!a_set[@]}"
> =>
> rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
> remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?

Well, that's what you get when you redirect stdin to null:

$ rm -i *
remove a? n
remove b? n
remove c? n
$ rm -i * </dev/null
remove a? remove b? remove c? $

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Subject: Re: Problem with 'rm -i' in ksh
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sat, 11 Jan 2025 15:16 UTC
References: 1 2
Path: news.eternal-september.org!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: Re: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 15:16:31 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vlu20f$2rlri$1@news.xmission.com>
References: <vlsqmt$fem4$1@dont-email.me> <slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
Injection-Date: Sat, 11 Jan 2025 15:16:31 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3004274"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>,
Christian Weisgerber <naddy@mips.inka.de> wrote:
>On 2025-01-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>
>> rm -i "${!a_set[@]}"
>> =>
>> rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
>> remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?
>
>Well, that's what you get when you redirect stdin to null:
>
>$ rm -i *
>remove a? n
>remove b? n
>remove c? n
>$ rm -i * </dev/null
>remove a? remove b? remove c? $

Yeah, that was my first reaction as well. But it seems so obvious, that it
seems unlikely that this particular poster would have fallen into that trap.

Maybe the script is being executed in some non-normal environment, say in
cron, or in an "init" script, where stdin is redirected to /dev/null.

A couple of other comments:

1) I've found out recently that, under certain, as yet undetermined,
conditions, scripts run from .profile have stdin == /dev/null.

2) I think that "rm" should (*) open up /dev/tty to prompt for yes/no,
rather than rely on standard input. It should fail/exit with an error
message if /dev/tty can't be opened (which will happen if the process has
no controlling terminal).

(*) "should" in the sense of does not now, but the world would be better if
it did.

--
"Insisting on perfect safety is for people who don't have the balls to live
in the real world."

- Mary Shafer, NASA Ames Dryden -

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 06:21 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 07:21:29 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <vlvn1a$1206d$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me>
<slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 07:21:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="48124128631fba90ea2113d9c43d2278";
logging-data="1114317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q8RimfCInLr0xTcTYPbJK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:4wLNYhSAqg8gHX4NErK/NkE+brQ=
In-Reply-To: <slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
View all headers

On 11.01.2025 15:01, Christian Weisgerber wrote:
> On 2025-01-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>
>> rm -i "${!a_set[@]}"
>> =>
>> rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
>> remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?
>
> Well, that's what you get when you redirect stdin to null:
>
> $ rm -i *
> remove a? n
> remove b? n
> remove c? n
> $ rm -i * </dev/null
> remove a? remove b? remove c? $
>

Yeah; only that I haven't any [explicit] redirection of stdin (let
alone a redirection to /dev/null).

But your suggestion reminds me to inspect the strace log; maybe I'll
find any hints on that...

Janis

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 06:40 UTC
References: 1 2 3
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 07:40:21 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <vlvo4m$124ks$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me>
<slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
<vlu20f$2rlri$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 07:40:23 +0100 (CET)
Injection-Info: dont-email.me; posting-host="48124128631fba90ea2113d9c43d2278";
logging-data="1118876"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4utwDWvlLcxcrjymtSQWU"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:+I4Ph053QV9d36jqnwluIFNXj7Y=
In-Reply-To: <vlu20f$2rlri$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
View all headers

On 11.01.2025 16:16, Kenny McCormack wrote:
> In article <slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>,
> Christian Weisgerber <naddy@mips.inka.de> wrote:
>> On 2025-01-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>>
>>> rm -i "${!a_set[@]}"
>>> =>
>>> rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
>>> remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?
>>
>> Well, that's what you get when you redirect stdin to null:
>>
>> $ rm -i *
>> remove a? n
>> remove b? n
>> remove c? n
>> $ rm -i * </dev/null
>> remove a? remove b? remove c? $
>
> Yeah, that was my first reaction as well. But it seems so obvious, that it
> seems unlikely that this particular poster would have fallen into that trap.

Sometimes it may be necessary to refresh an old man's brain. ;-)
But you are right, I'd have noticed such suspicious redirections.

>
> Maybe the script is being executed in some non-normal environment, say in
> cron, or in an "init" script, where stdin is redirected to /dev/null.

Yeah, something that I also thought about. - But in this case it's
just a normally run script (tested in ~/bin through PATH search and
with explicit ksh interpreter). - Here I thought more about any fancy
changes in ~/.profile or ~/.kshrc that might have affected behavior.
But yet I haven't spotted anything apparent; environments get overly
complex, though.

>
> A couple of other comments:
>
> 1) I've found out recently that, under certain, as yet undetermined,
> conditions, scripts run from .profile have stdin == /dev/null.

Well, I'd not really expect interactive input in .profile, but if it's
not specified that is or would be bad.

> 2) I think that "rm" should (*) open up /dev/tty to prompt for yes/no,
> rather than rely on standard input. It should fail/exit with an error
> message if /dev/tty can't be opened (which will happen if the process has
> no controlling terminal).

Indeed. - But thinking about that... - using stdin might be considered
advantageous if one wants to connect a controlling tool (say, an AI -
LOL) to judge/control the command. Quite unlikely its usefulness, but
that's the one thing that occurred to me for such a design.

Janis

>
> (*) "should" in the sense of does not now, but the world would be better if
> it did.
>

Subject: Re: Problem with 'rm -i' in ksh
From: Keith Thompson
Newsgroups: comp.unix.shell
Organization: None to speak of
Date: Sun, 12 Jan 2025 07:14 UTC
References: 1 2
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sat, 11 Jan 2025 23:14:42 -0800
Organization: None to speak of
Lines: 35
Message-ID: <87h664jyfx.fsf@nosuchdomain.example.com>
References: <vlsqmt$fem4$1@dont-email.me>
<slrnvo4udu.a76.naddy@lorvorc.mips.inka.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 12 Jan 2025 08:15:15 +0100 (CET)
Injection-Info: dont-email.me; posting-host="e09f1c48d05ea16eba68b16586b9febd";
logging-data="1121884"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+52PlDateDPrs0+Ix+M/gS"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:W3vaIxlU7Yg749oZLXOWX5otjNg=
sha1:lQ4JjuNtAeH3XCQnOt5/WM46i0c=
View all headers

Christian Weisgerber <naddy@mips.inka.de> writes:
> On 2025-01-11, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> rm -i "${!a_set[@]}"
>> =>
>> rm: remove regular file `rmd2'? rm: remove regular file `rmd4'? rm:
>> remove regular file `rmd9 2'? rm: remove regular file `rmd9 3'?
>
> Well, that's what you get when you redirect stdin to null:
>
> $ rm -i *
> remove a? n
> remove b? n
> remove c? n
> $ rm -i * </dev/null
> remove a? remove b? remove c? $

Which raises the question of what rm -i *should* do if stdin isn't
a tty.

POSIX specifically says that "rm shall write a prompt to standard
error and read a line from the standard input".

Changing the current behavior would (a) violate POSIX, and (b) break
usages like "yes | some_script", where "some_script" invokes rm -i.
The current behavior is well defined, even if it may not be ideal.

I can see the usefulness of, for example, bailing out with an error
message if stdin is not a tty or repeating the prompt if the input is
neither 'y' nor 'n' (or whatever the locale-specific equivalents are),
but if you want that you can program it yourself (or add it as a
non-standard option to rm).

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Subject: Re: Problem with 'rm -i' in ksh
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 11:05 UTC
References: 1 2 3
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 11:05:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <vm07mh$13cnk$5@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vltjc3$htgh$1@dont-email.me>
<vlttua$la3m$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 12 Jan 2025 12:05:53 +0100 (CET)
Injection-Info: dont-email.me; posting-host="092d2d6496192b42037dbb3a1e348163";
logging-data="1159924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MiFvvXA6vS3wtcDGRl+CnSwzKIBbCvXg="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:KEH4/m60GTeqnAmog5Eqdd2YmAs=
View all headers

Il Sat, 11 Jan 2025 15:07:05 +0100, Janis Papanagnou ha scritto:

> Yes, just these commands in a script work also in my environment. (That
> was what I meant when I wrote: "constructing a test sample from
> scratch";
> it didn't lead me anywhere, since it just wasn't reproducible in a
> primitive context like that.)
>
> I think it must have to do with the shell environment that in some way
> affects how 'rm -i' behaves. But I have no idea how an external
> (shell-environment-)condition could look like that makes an executed
> program like 'rm' behave as if all '-i' confirmations are "magically"
> considered as being each answered by "no" (without me typing anything).

Oh, I'm sorry for my mistake.

Letting alone the redirection of standard input, or the "cron or whatever"
hypothesis, that didn't seem to fit your situation, and since the command
works well itself in a primitive context, it seem strange to me that the
cause can be found in your ksh configuration, too...

So, I can't think of anything... which doesn't impress me much: it happens
frequently. ;)

However: if you add in the script "< /dev/tty" as in

rm -i file < /dev/tty

does it make any change?

rm -i is called in a pipe? Exec? Subshell?

I know you know. I'm out of ideas.
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 13:04 UTC
References: 1 2 3 4
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 14:04:41 +0100
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <vm0ela$15i9h$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vltjc3$htgh$1@dont-email.me>
<vlttua$la3m$1@dont-email.me> <vm07mh$13cnk$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 14:04:42 +0100 (CET)
Injection-Info: dont-email.me; posting-host="c3d140746c7c5fdf39b74eedc856b652";
logging-data="1231153"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JxaVcC9FkWN/DGZPdzOC1"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:WAsWBf5vk2lDYYLDwoUbpf/BXJs=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vm07mh$13cnk$5@dont-email.me>
View all headers

On 12.01.2025 12:05, Lem Novantotto wrote:
> Il Sat, 11 Jan 2025 15:07:05 +0100, Janis Papanagnou ha scritto:
>
>> Yes, just these commands in a script work also in my environment. (That
>> was what I meant when I wrote: "constructing a test sample from
>> scratch";
>> it didn't lead me anywhere, since it just wasn't reproducible in a
>> primitive context like that.)
>>
>> I think it must have to do with the shell environment that in some way
>> affects how 'rm -i' behaves. But I have no idea how an external
>> (shell-environment-)condition could look like that makes an executed
>> program like 'rm' behave as if all '-i' confirmations are "magically"
>> considered as being each answered by "no" (without me typing anything).
>
> Oh, I'm sorry for my mistake.

No worries. :-)

>
> Letting alone the redirection of standard input, or the "cron or whatever"
> hypothesis, that didn't seem to fit your situation, and since the command
> works well itself in a primitive context, it seem strange to me that the
> cause can be found in your ksh configuration, too...
>
> So, I can't think of anything... which doesn't impress me much: it happens
> frequently. ;)
>
> However: if you add in the script "< /dev/tty" as in
>
> rm -i file < /dev/tty
>
> does it make any change?

Erm, yes. - Then it just works. :-)

I'm now feeling a bit stupid; we were discussing the effect of some
(possibly invisible) redirection without me taking the constructive
approach to just invent that redirection as you propose it. Thanks!

The previously observed effect still unsettles me, but since I want
just a working solution the simple workaround/fix is perfect!

>
> rm -i is called in a pipe? Exec? Subshell?

It's called in a (ksh-)function within a structure like this

function f { ... rm ... }
p1 | p2 | while read ... do ... f ... done
f

>
> I know you know. I'm out of ideas.

One fitting idea suffices :-) - Thanks again!

Janis

Subject: Re: Problem with 'rm -i' in ksh
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sun, 12 Jan 2025 14:14 UTC
References: 1 2 3 4
Path: news.eternal-september.org!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: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 14:14:18 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vm0inq$2st9j$1@news.xmission.com>
References: <vlsqmt$fem4$1@dont-email.me> <vlttua$la3m$1@dont-email.me> <vm07mh$13cnk$5@dont-email.me> <vm0ela$15i9h$1@dont-email.me>
Injection-Date: Sun, 12 Jan 2025 14:14:18 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3044659"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <vm0ela$15i9h$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
....
>It's called in a (ksh-)function within a structure like this
>
> function f { ... rm ... }
> p1 | p2 | while read ... do ... f ... done
> f

Well, that explains everything.

And you're going to get a dozen responses just like this one, pointing
out the obvious.

When you are in a "... | while read" loop, the stuff inside the while loop
has stdin coming from the pipe. Yes, I've been bitten by this a few times,
and it is one of the (many) reasons I avoid the "... | while read" idiom.
There are always better/cleaner alternatives.

BTW, I was going to suggest that the best way to debug this was, assuming
you're running Linux, to add code just before the "rm" to do a "ls -lsa
/proc/self/fd/0" and you'll then know what fd 0 is. My guess is that that
would show that fd 0 is something like: /proc/self/fd/0 -> pipe:[123456789]

A couple of comments:

1) Keith made some good points about the possibility of changing how
"rm" behaves when stdin is not a tty. Looks like we'll have to get
POSIX changed before we can change the program, although the idea
of adding a new flag (maybe -I instead of (i.e., in addition to) -i)
has merit.

2) I've always thought that adding -i to rm as a safety feature was a
bad idea. This is a total aside, but it seems common for system
admins to setup a global alias that aliases "rm" to "rm -i". It
seems to me that if you want to make "rm" safer, you should alias
it to "rm -v" instead. "rm -i" makes it hard to do large deletes
(like removing a whole directory) - since you get prompted over and
over and over. With "rm -v", the users will know what they've done
and will learn quick to be careful. I.e., the real danger with
"rm" without "-v" is that you can delete stuff without knowing it,
and only find out (much) later.

--
Religion is what keeps the poor from murdering the rich.

- Napoleon Bonaparte -

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 15:39 UTC
References: 1 2 3 4 5
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 16:39:49 +0100
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vm0no6$17127$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vlttua$la3m$1@dont-email.me>
<vm07mh$13cnk$5@dont-email.me> <vm0ela$15i9h$1@dont-email.me>
<vm0inq$2st9j$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 16:39:51 +0100 (CET)
Injection-Info: dont-email.me; posting-host="c3d140746c7c5fdf39b74eedc856b652";
logging-data="1279047"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WguYibdUQzZxY/NwvlAPO"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:qofg4DRMd/k9hPJ6juRa9RuGSXE=
In-Reply-To: <vm0inq$2st9j$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
View all headers

On 12.01.2025 15:14, Kenny McCormack wrote:
> In article <vm0ela$15i9h$1@dont-email.me>,
> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
> ...
>> It's called in a (ksh-)function within a structure like this
>>
>> function f { ... rm ... }
>> p1 | p2 | while read ... do ... f ... done
>> f
>
> When you are in a "... | while read" loop, the stuff inside the while loop
> has stdin coming from the pipe.

First I thought you meant bash's sub-shell issue (which isn't present
in ksh). But you are right about stdin; I completely missed that. Doh!
Thanks for spotting that!

> Yes, I've been bitten by this a few times,
> and it is one of the (many) reasons I avoid the "... | while read" idiom.
> There are always better/cleaner alternatives.

(I know that you can circumvent bash's sub-shell issue with while/read
e.g. by using process substitution

while read ... do ... f ... done < <( p1 | p2 )

But - in case you were thinking about that idiom - that would not solve
the redirection issue.)

One way to fix the redirection issue would be to duplicate the 'stdin'
file descriptor; to start the script with
exec 4<&0
and then call the remove command referring explicitly to that other FD
using
0<&4 /bin/rm -i ...

What (other, "better/cleaner") idioms were you thinking of?

Janis

Subject: Re: Problem with 'rm -i' in ksh
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 16:08 UTC
References: 1 2 3 4 5 6
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 17:08:03 +0100
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <vm0pd4$17ar8$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vlttua$la3m$1@dont-email.me>
<vm07mh$13cnk$5@dont-email.me> <vm0ela$15i9h$1@dont-email.me>
<vm0inq$2st9j$1@news.xmission.com> <vm0no6$17127$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 17:08:04 +0100 (CET)
Injection-Info: dont-email.me; posting-host="c826e18720b6da4495e24856fed325dd";
logging-data="1289064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Uy1f60+AEZvnXzQOW3a4g"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:h4wSqGmOhrfW8EMNQy9OYCK8q2k=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vm0no6$17127$1@dont-email.me>
View all headers

On 12.01.2025 16:39, Janis Papanagnou wrote:
> On 12.01.2025 15:14, Kenny McCormack wrote:
>> In article <vm0ela$15i9h$1@dont-email.me>,
>> Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>> ...
>>> It's called in a (ksh-)function within a structure like this
>>>
>>> function f { ... rm ... }
>>> p1 | p2 | while read ... do ... f ... done
>>> f
>>
>> When you are in a "... | while read" loop, the stuff inside the while loop
>> has stdin coming from the pipe.

BTW; there's two calls of 'f', one in the loop (without stdin),
the other outside (supposedly having stdin). - I wonder why the
latter also didn't work; it neither showed the flushed data nor
interrogated the interactive confirmation for the final data.
(Am I still missing something?)

Janis

Subject: Re: Problem with 'rm -i' in ksh
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 12 Jan 2025 22:01 UTC
References: 1 2 3 4 5 6 7
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Problem with 'rm -i' in ksh
Date: Sun, 12 Jan 2025 22:01:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <vm1e35$184ks$1@dont-email.me>
References: <vlsqmt$fem4$1@dont-email.me> <vlttua$la3m$1@dont-email.me>
<vm07mh$13cnk$5@dont-email.me> <vm0ela$15i9h$1@dont-email.me>
<vm0inq$2st9j$1@news.xmission.com> <vm0no6$17127$1@dont-email.me>
<vm0pd4$17ar8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 12 Jan 2025 23:01:10 +0100 (CET)
Injection-Info: dont-email.me; posting-host="092d2d6496192b42037dbb3a1e348163";
logging-data="1315484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IszjdLEryybbyYhHfbU7FL4fnarH3WPg="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:y1lmy0C6YIF7VynPsTRVy9qsthI=
View all headers

Il Sun, 12 Jan 2025 17:08:03 +0100, Janis Papanagnou ha scritto:

> BTW; there's two calls of 'f', one in the loop (without stdin),
> the other outside (supposedly having stdin). - I wonder why the latter
> also didn't work; it neither showed the flushed data nor interrogated
> the interactive confirmation for the final data.

Edgar Allan Janis Doyle: "Mystery tales of the KSH (Kernel BaskerScript
Hound)", where every function and variable leads us deeper into the
enigmatic labyrinth of the shell's secrets. ;-)

We need a Sherlock Holmes, for sure! :-)
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Mon, 13 Jan 2025 02:54 UTC
References: 1 2 3 4
Path: news.eternal-september.org!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)
View all headers

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.

Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 13 Jan 2025 09:08 UTC
References: 1 2 3 4 5
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
Date: Mon, 13 Jan 2025 10:08:54 +0100
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <vm2l77$1ni2s$1@dont-email.me>
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>
<vm1v8a$2tk9v$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 13 Jan 2025 10:08:56 +0100 (CET)
Injection-Info: dont-email.me; posting-host="5b3599e30b8a81050b6cf7719714923d";
logging-data="1820764"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GP9cr+G9LY67OIJXn6i/C"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:j+aWr+KHSxqXoHYAUtzx6YL/nxA=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vm1v8a$2tk9v$1@news.xmission.com>
View all headers

On 13.01.2025 03:54, Kenny McCormack wrote:
>
> In general, when I need to iterate over a set (in bash), I use "mapfile".
> [...]
> I think more or less the same is available in ksh.

Not that I'd know of. - Maybe getting something similar using some
standard mechanisms? - If I understand 'mapfile' correctly it may
(basically) do something like IFS=$'\n' arr=( $( ... ) ) ?

>
> 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.

In case stdin is not a terminal I'd not expect the flushing of the
prompts; in case that condition is even checked I'd rather expect
a warning message. (But I haven't thought about that to any depth.)

Janis

> [...]

Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 13 Jan 2025 20:39 UTC
References: 1 2 3 4 5
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
Date: Mon, 13 Jan 2025 20:39:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <vm3tmq$20qtd$1@dont-email.me>
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>
<vm1v8a$2tk9v$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Jan 2025 21:39:54 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7b4523ae5049bb493c8bce97e3a45f1f";
logging-data="2124717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hD/LmBwXrI+5LhckUGjEXpuHofEbYIDE="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:uSEsVB4ezyF1euFKNq2gB7VvwGI=
View all headers

Il Mon, 13 Jan 2025 02:54:02 -0000 (UTC), Kenny McCormack ha scritto:

> So, instead of:
>
> ... | while read ...
>
> I will do:
>
> mapfile -t < <(...)
> for i in "${MAPFILE[@]}"; do
> ...
> done

Your solution has its advantages, but IMHO it has many drawbacks too.
It's more memory consuming, less portable, it doesn't react promptly...
And you cannot follow and process in real time a streams, of course.
You cannot do something like:

$ while true; do echo yes; done |while read $w; do echo "$w and no"; done
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Mon, 13 Jan 2025 20:42 UTC
References: 1 2 3 4 5 6
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)
Date: Mon, 13 Jan 2025 20:42:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <vm3ts3$20qtd$2@dont-email.me>
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>
<vm1v8a$2tk9v$1@news.xmission.com> <vm3tmq$20qtd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 13 Jan 2025 21:42:43 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7b4523ae5049bb493c8bce97e3a45f1f";
logging-data="2124717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/io4uLmCDfrhSxl4agHp2hEgy+5B2WWhc="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:vrRya5Ky9CcB2SzowOw7nnhOlu8=
View all headers

Il Mon, 13 Jan 2025 20:39:54 -0000 (UTC), Lem Novantotto ha scritto:

some typos

...stream...

...while read w; do echo "$w and no"; done...

Sorry.
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Re: Iterating over a set in bash
From: Keith Thompson
Newsgroups: comp.unix.shell
Organization: None to speak of
Date: Tue, 14 Jan 2025 01:13 UTC
References: 1 2 3 4 5 6
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Keith.S.Thompson+u@gmail.com (Keith Thompson)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash
Date: Mon, 13 Jan 2025 17:13:06 -0800
Organization: None to speak of
Lines: 12
Message-ID: <87bjwa9p0d.fsf@nosuchdomain.example.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>
<vm1v8a$2tk9v$1@news.xmission.com> <vm3tmq$20qtd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 14 Jan 2025 02:13:07 +0100 (CET)
Injection-Info: dont-email.me; posting-host="b949980cf0e823ed5c5fd65edca1d2ec";
logging-data="2230601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lSjEuM+OhfghUA3Jo7W2D"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:VZA0fyEoKKylhOzoHXDLYoNEqfA=
sha1:pdxIMHptyv65c+zGMku5BsdM+nk=
View all headers

Lem Novantotto <Lem@none.invalid> writes:
[...]
> $ while true; do echo yes; done |while read $w; do echo "$w and no"; done

"while true; do echo yes; done" can be equivalently written as "yes yes".

The "yes" command prints its arguments repeatedly. With no argument, it
prints "y" repeatedly.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Subject: Re: Iterating over a set in bash
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Tue, 14 Jan 2025 09:08 UTC
References: 1 2 3 4 5 6 7
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash
Date: Tue, 14 Jan 2025 09:08:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vm59jb$2b9fo$1@dont-email.me>
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>
<vm1v8a$2tk9v$1@news.xmission.com> <vm3tmq$20qtd$1@dont-email.me>
<87bjwa9p0d.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 Jan 2025 10:08:59 +0100 (CET)
Injection-Info: dont-email.me; posting-host="c2826baae225664ec57c6bdb8ed0a290";
logging-data="2467320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hAwo2KH0oIH/g5IlIVs+kba9BK/UKJuU="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:HGhchW5PfxBIIkEdzmLNkWpcYa8=
View all headers

Il Mon, 13 Jan 2025 17:13:06 -0800, Keith Thompson ha scritto:

> "while true; do echo yes; done" can be equivalently written as "yes
> yes".

(true && false || (yes yes | while read line; do echo -n "$line "; count=$((count + 1)); if [ "$count" -eq 2 ]; then echo; break; fi; done | sed -e 's/^./\U&/' -e 's/ /, /'| head -n 1 && echo "is much better." && sleep 1 && seq 1 1 | tail -n 1 > /dev/null && cat /dev/zero | head -c 0 && printf " Thanks. ;-)))\n")) | tr -d '\n'; echo
--
Bye, Lem
Talis erit dies qualem egeris

Subject: Re: Iterating over a set in bash
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Tue, 14 Jan 2025 10:21 UTC
References: 1 2 3 4 5 6 7 8
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Iterating over a set in bash
Date: Tue, 14 Jan 2025 11:21:12 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <vm5dqq$2ca7b$1@dont-email.me>
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>
<vm1v8a$2tk9v$1@news.xmission.com> <vm3tmq$20qtd$1@dont-email.me>
<87bjwa9p0d.fsf@nosuchdomain.example.com> <vm59jb$2b9fo$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Jan 2025 11:21:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3244c3cf7af00d5f2b161a466407d110";
logging-data="2500843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fM1CqeKYAMbo3hSFfisOS"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:oJC0gp3LnU9b6whf+sDWYvr3lco=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <vm59jb$2b9fo$1@dont-email.me>
View all headers

On 14.01.2025 10:08, Lem Novantotto wrote:
> Il Mon, 13 Jan 2025 17:13:06 -0800, Keith Thompson ha scritto:
>
>> "while true; do echo yes; done" can be equivalently written as "yes
>> yes".
>
> (true && false || (yes yes | while read line; do echo -n "$line "; count=$((count + 1)); if [ "$count" -eq 2 ]; then echo; break; fi; done | sed -e 's/^./\U&/' -e 's/ /, /'| head -n 1 && echo "is much better." && sleep 1 && seq 1 1 | tail -n 1 > /dev/null && cat /dev/zero | head -c 0 && printf " Thanks. ;-)))\n")) | tr -d '\n'; echo

LOL! - It's good I have an interpreter to understand that answer
without the necessity for a code analysis. ;-)

Janis

1

rocksolid light 0.9.8
clearnet tor