Re: Problem with 'rm -i' in ksh

Liste des GroupesRevenir à cu shell 
Sujet : Re: Problem with 'rm -i' in ksh
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 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


Date Sujet#  Auteur
11 Jan 25 * Problem with 'rm -i' in ksh21Janis Papanagnou
11 Jan 25 +* Re: Problem with 'rm -i' in ksh15Lem Novantotto
11 Jan 25 i`* Re: Problem with 'rm -i' in ksh14Janis Papanagnou
12 Jan 25 i `* Re: Problem with 'rm -i' in ksh13Lem Novantotto
12 Jan 25 i  `* Re: Problem with 'rm -i' in ksh12Janis Papanagnou
12 Jan 25 i   `* Re: Problem with 'rm -i' in ksh11Kenny McCormack
12 Jan 25 i    `* Re: Problem with 'rm -i' in ksh10Janis Papanagnou
12 Jan 25 i     +* Re: Problem with 'rm -i' in ksh2Janis Papanagnou
12 Jan 25 i     i`- Re: Problem with 'rm -i' in ksh1Lem Novantotto
13 Jan 25 i     `* Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)7Kenny McCormack
13 Jan 25 i      +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)1Janis Papanagnou
13 Jan 25 i      `* Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)5Lem Novantotto
13 Jan 25 i       +- Re: Iterating over a set in bash (Was: Problem with 'rm -i' in ksh)1Lem Novantotto
14 Jan 25 i       `* Re: Iterating over a set in bash3Keith Thompson
14 Jan 25 i        `* Re: Iterating over a set in bash2Lem Novantotto
14 Jan 25 i         `- Re: Iterating over a set in bash1Janis Papanagnou
11 Jan 25 `* Re: Problem with 'rm -i' in ksh5Christian Weisgerber
11 Jan 25  +* Re: Problem with 'rm -i' in ksh2Kenny McCormack
12 Jan 25  i`- Re: Problem with 'rm -i' in ksh1Janis Papanagnou
12 Jan 25  +- Re: Problem with 'rm -i' in ksh1Janis Papanagnou
12 Jan 25  `- Re: Problem with 'rm -i' in ksh1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal