Sujet : Re: Problem with 'rm -i' in ksh
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 12. Jan 2025, 16:39:49
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vm0no6$17127$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
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