#!/bin/sh basedir="/tmp/pipechat" [ -d $basedir ] || { mkdir $basedir chmod 777 $basedir } [ -p $basedir/${USER} ] || { mkfifo $basedir/${USER} chmod 622 $basedir/${USER} } while true; do cat $basedir/$USER; done & listen_pid=$! choice="" choice2="" while [ "$choice" != ":quit" ] do echo "Type an available user or ':quit' to exit." echo "Available users:" ls $basedir read choice [ -p $basedir/$choice ] && { clear echo "Chat with $choice. --- Type ':quit' to exit" while true do read choice2 case $choice2 in :quit) break ;; :help) echo "Type :quit to quit." ;; #*) printf "\e[0;36m${USER}: $choice2\e[m\n" > $basedir/$choice ;; *) printf "${USER}: $choice2\n" > $basedir/$choice ;; esac done } [ -p $basedir/$choice ] || [ "$choice" = ":quit" ] || echo "$choice is not an available user" done kill $listen_pid