Deutsch English Français Italiano |
<vm0inq$2st9j$1@news.xmission.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!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) Bytes: 2922 Lines: 47 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 -