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.)
11:59:35<lem@biggy:/tmp/prova$ cat mioscript#!/bin/ksh
11:59:43<lem@biggy:/tmp/prova$ ./mioscriptfile1 file2 file3 3
12:00:28<lem@biggy:/tmp/prova$ ksh ./mioscriptfile1 file2 file3 3
12:00:38<lem@biggy:/tmp/prova$ ksh --versionversion sh (AT&T Research) 93u+m/1.0.8 2024-01-01
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$ ./mioscriptfile1 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 ./mioscriptfile1 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 --versionversion sh (AT&T Research) 93u+m/1.0.8 2024-01-01
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'?
On 2025-01-11, Janis Papanagnou <[email protected]> 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? $
In article <[email protected]>,
Christian Weisgerber <[email protected]> wrote:
On 2025-01-11, Janis Papanagnou <[email protected]> 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.
On 2025-01-11, Janis Papanagnou <[email protected]> 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? $
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).
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.
It's called in a (ksh-)function within a structure like this
function f { ... rm ... }
p1 | p2 | while read ... do ... f ... done
f
In article <vm0ela$15i9h$[email protected]>,
Janis Papanagnou <[email protected]> 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.
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.
On 12.01.2025 15:14, Kenny McCormack wrote:
In article <vm0ela$15i9h$[email protected]>,
Janis Papanagnou <[email protected]> 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.
What (other, "better/cleaner") idioms were you thinking of?
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.
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.
[...]
So, instead of:
... | while read ...
I will do:
mapfile -t < <(...)
for i in "${MAPFILE[@]}"; do
...
done
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 714 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 135:13:14 |
| Calls: | 12,087 |
| Files: | 14,997 |
| Messages: | 6,517,362 |