UNIX chat shell code


As most UNIX bods know, with fairly recent audit lock downs – talkd has been disabled.

But you want to chat remotely with someone, i.e. another techie bod! 🙂



Now where is the fun in that! 🙂

Don’t know about you, but quite often I’ve needed to talk to other people remotely and don’t want to hold a phone or use hands free.

See the example.



Here is a quick and dirty solution, that works with bash – should work with zsh too.

I welcome any enhancements or suggestions, via the comments.


trap 'kill $tailpid;echo "*$nick leaves chat*" >> ${chatdir}/discussion;
rm ${chatdir}/.${nick};exit 0' 2


[ -d $chatdir ] || {
mkdir $chatdir || (echo "failed to mkdir $chatdir";exit 1)

chmod 777 /var/tmp/unixchat

while [ $(echo X${nick} | grep -c "^X$") -eq 1 ]
echo -n "Nick: "
read nick

[ -f "${chatdir}/.${nick}" ] && {
echo "$nick already exists, try another";nick=""


touch ${chatdir}/.${nick}

[ ! -f ${chatdir}/discussion ] && {
touch ${chatdir}/discussion
chmod 666 ${chatdir}/discussion

echo "*$nick joins chat*" >> ${chatdir}/discussion

tail -1000f ${chatdir}/discussion&

echo ">> type quit to exit <<"

while [ $(echo X${entry} | grep -c "^Xquit$") -ne 1 ]
read entry
echo "[${nick}@`date '+%d-%b %H:%M:%S'`] says: $entry" >> ${chatdir}/discussion&


kill $tailpid; rm ${chatdir}/.${nick}

echo "*$nick leaves chat*" >> ${chatdir}/discussion

exit 0

Here is a screen shot:

UNIX chat code - simple solution written in shell



[tags]UNIX, Chat code, Shell Script[/tags]


If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *