I apparently wrote this last May.  I'd forgotten about it.  It more or
less works, but of course it isn't secure or very featureful, there's
a propagation delay averaging about half a second, it's wasteful of
cycles, and it doesn't have good error handling.  In particular,
killing it with control-C will not notify others that you exited.
Also, it produces a file that grows without bound and logs your chats.

Also, like most of my shell programs, it's excessively paranoid, it
uses Perl where perhaps sed (or, other times, awk) would be better,
and it uses kshisms where it doesn't need to, so it won't run under a
real Bourne shell.  (If you are so unfortunate as to be on a system
with a real Bourne shell, run it with ksh.)

Still, for all its weaknesses, it demonstrates beautifully how
convenient, flexible, and productive the Unix shell can be.  We still
don't have anything like this for the Web.  KnowNow's JavaScript stuff
is coming close, but it's still proprietary, and it's often still far
clumsier than this.

Paul Graham writes that C programmers switching to Lisp often write
slow code because they think that, when a program works, it's done ---
but it often works much sooner in Lisp than it would in C, but it
still needs a lot of tuning to make it fast.  Perhaps this illustrates
something analogous for sh --- not only is it not fast, it's not very
correct, but it works for a useful subset of cases.  This is often my
experience with sh programs.

#!/bin/sh
: ${CHANNEL:=/tmp/chatchan}
touch "$CHANNEL" 2>/dev/null
chmod 666 "$CHANNEL" 2>/dev/null
tail -0f "$CHANNEL" &
tailpid="$?"
: ${NICK:=$(id -un)}
trap "kill '$tailpid'" 0
echo "-- $NICK joins" >> "$CHANNEL"
perl -pe '$|=1; s/^/<'"$NICK"'> /' >> "$CHANNEL"
echo "-- $NICK quits" >> "$CHANNEL"

-- 
<[EMAIL PROTECTED]>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
A good conversation and even lengthy and heated conversations are probably
some of the most important pointful things I can think of.  They are the
antithesis of pointlessness!  -- Matt O'Connor <[EMAIL PROTECTED]>


Reply via email to