From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25418 invoked from network); 4 Dec 2000 00:08:43 -0000 Received: from sunsite.dk (HELO sunsite.auc.dk) (130.225.51.30) by ns1.primenet.com.au with SMTP; 4 Dec 2000 00:08:43 -0000 Received: (qmail 13646 invoked by alias); 4 Dec 2000 00:08:28 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3546 Received: (qmail 13639 invoked from network); 4 Dec 2000 00:08:26 -0000 To: "Zsh Users' List" Subject: Re: Better ( rm foo; bar > foo ) < foo ? References: <87n1edeh8c.fsf@senstation.vvf.fi> <1001203174821.ZM12458@candle.brasslantern.com> Mail-Followup-To: zsh-users@sunsite.auc.dk Mail-copies-to: never From: Hannu Koivisto Date: 04 Dec 2000 01:17:58 +0200 In-Reply-To: <1001203174821.ZM12458@candle.brasslantern.com> Message-ID: <873dg5drh5.fsf@senstation.vvf.fi> User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: Hannu Koivisto "Bart Schaefer" writes: | How about | | mv -i =(bar < foo) foo At first I thought this is cool and very close to what I was looking for but... | ?? As long as `bar' produces some kind of failure output, that should be OK ...it seems you mean I have to have that -i there and wait and see if bar says something went wrong and then tell mv not to overwrite. A little test seems to indicate this is indeed how =() works, i.e. without -i it would run mv even if bar returns false. I think I prefer your rewrite suggestion below. | A little more input on what you think would NOT be clumsy would help. For That three-liner I wrote is too clumsy for throw-away-scripting; I guess I was fantasizing about something like sed 's/foo/bar/g' <> foo (with something else in place of <> since that seems to be in use already) but I think anything that keeps one-liners as one-liners is ok, like that rewrite below. | example, would | | rewrite sed 's/foo/bar/g' foo | be OK? Just take your original "in a script, I'd probably write" and put It would be ok. | it in a function: | | rewrite() { | local TMPFILE=${TMPPREFIX}rewrite.$$ # Whatever | $argv[1,-2] < $argv[-1] > $TMPFILE || rm -f $TMPFILE | [[ -f $TMPFILE ]] && mv -f $TMPFILE $argv[-1] | } Thanks, this is what I thought of first too, but I got greedy and I wanted the hypothetical ideal way to work so that I could also redirect the output to another place at the same time, i.e. something like sed 's/foo/bar/g' <> foo > bar | baz and I couldn't figure out how to include that to such function-approach as rewrite, so I dropped the idea, but, well, I guess that rewrite is just fine after all. Clint Adams writes: | I find that | | perl -pi -e 's/foo/bar/g' $FILE | | is much less of a hassle, if that's the complexity you're dealing with. I find that Perl equals to pain, so I try to avoid it any way I can (fortunately there is no Perl for my new machine, I think) :) In any case, that sed thing was just an example, I was trying to find a general way. Thanks anyway, -- Hannu