#!/bin/bash set -e if [ $# -eq 2 ]; then user="$(whoami)_$(hostname)" channel="$1" message="$2" elif [ $# -eq 3 ]; then user="$1" channel="$2" message="$3" else echo 'Need 2 or 3 arguments: (user) channel message.' exit 1 fi pid='' clean_up() { rm -rf --one-file-system "${tmp_dir}" if [ -n "${pid}" ]; then kill ${pid} fi } tmp_dir="$(mktemp -d)" trap clean_up EXIT mkfifo "${tmp_dir}/input" mkfifo "${tmp_dir}/output" ncat irc.home.eckner.net 6667 < \ "${tmp_dir}/input" > \ "${tmp_dir}/output" & pid=$! ( printf '%s\n' 'NICK '"${user}" 'USER '"${user}"' 8 * : '"${user}" while read -r s; do echo "$s" >&2 if [[ "${s}" = *"MODES"* ]]; then printf '%s\n' 'JOIN '"${channel}" 'PRIVMSG '"${channel}"' :'"${message}" 'QUIT' fi done \ < "${tmp_dir}/output" ) \ > "${tmp_dir}/input" unset pid