Authored by Zygo Blaxell

IRC messages from the command line

These scripts are simple IRC clients which read a message from stdin and send it to an IRC destination, which can be a nick (e.g. "Zygo") or a channel (e.g. "#oclug"). The primary difference between them is the length of the message that can be sent.

These are simple IRC clients, so they do not handle non-simple cases. If source is already used by another client on the IRC server a nick collision occurs, and no message will be sent. Similarly passwords, NickServ registration, network timeouts, rate limits, intentionally uncooperative servers, and many other errors, specific configurations, and exceptional conditions are not handled.


Both scripts are written in Tcl and require the 'tclsh' executable to be installed, and the 'tcllib' package for the IRC library.

Single-line messages

send-irc [destination [source]]
sends a single line message to destination from source.

For historical reasons, if a multi-line message is given, it will first remove any text that appears before the first blank input line, then replace all newlines with spaces (the historical reason is that it is meant to send the bodies of email messages). If there are multiple lines but none of them are blank, then no text is removed, and newlines are simply replaced with spaces.

Multi-line messages

send-irc-long [-destination #destination]
[-source source]
[-serverPort 6667]
[-join 1]
sends a multi-line message read from STDIN as a series of IRC messages. The source, destination, IRC server host and port are given as command-line arguments.

By default, send-irc-long JOINs an IRC channel before sending messages to it. This behavior can be controlled using the -join option: a false value (0) indicates the channel should not be joined, while a true value (non-zero) indicates the channel shall be joined. When sending messages to other IRC nicks (as opposed to channels), the -join flag is mostly irrelevant, except that the IRC server will generate a few extra error messages.

Other notes:

  1. Most public IRC channels do not accept messages from users who have not JOINed them (this is controlled by the "n" channel mode flag). Some IRC server software makes this the default for all new channels, even if the IRC server is used privately behind a firewall.
  2. send-irc-long will JOIN a channel even if there are no messages to send from stdin. This will appear in the channel as a JOIN command immediately followed by a QUIT.
  3. send-irc-long does no rate limiting. It is usually necessary to throttle the standard input to avoid being kicked for flooding, for example like this:
    	# Replace "..." with commands to generate text to send on IRC
    	... | while read line; do
    		echo "$line"
    		sleep 2
    	done | send-irc-long -source ...
    	# Replace "..." above with IRC nick and other connection details