CLI Blogging code

Bookmark this category
How it’s done. I started out with a bash function as described earlier. The function code is below:
function blog() { echo "$2" | mail -s "$1" address@example.com; }

Then I noticed I would need more freedom to write longer text, without leaving the shell. So here goes the “blog” bash script. I’m using the postie wordpress plugin on the server side, so things are a bit more manageable. I may add more to this later if I get time.

#!/bin/bash
if [ -n "$2" ]; then
BODY=$2
else
vi tmpfile; BODY=`cat tmpfile`; rm tmpfile
fi
if [ -n "$1" ]; then
SUBJECT=$1
else
echo -n "Subject:"; read SUBJECT
fi
echo "$BODY" | mail -s "$SUBJECT" address@example.com

Similar Posts:

Tagged

Leave a Reply

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