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

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



Greetings,

If I needed to, say, modify some file with sed in a script, I'd
probably write something like this:

TMPFILE=$(mktemp "$(dirname "$FILE")/XXXXXX") || exit 1
sed 's/foo/bar/g' < "$FILE" > "$TMPFILE" || { rm -f "$TMPFILE" ; exit 1 }
mv "$TMPFILE" "$FILE"

This is quite clumsy (even if I removed some of the safety) and
thus the trick shown on the subject is quite appealing especially
in interactive use.  Unfortunately it has the problem that if bar
fails, the data is lost.  Besides, even it is a bit clumsier than
I'd like.

So, I started to ponder if zsh could help here.  Unfortunately I
couldn't come up with any nice "wrapping" of the functionality
above with a function or other existing zsh features, only a
thought of whether it would be possible to create some sort of new
redirection syntax that would do the trick.

What do you think?

-- 
Hannu



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