Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Better ( rm foo; bar > foo ) < foo ?



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> 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 <schizo@xxxxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author