I did some fine tuning on the command line, and this one should be an even better alternative:
ip -4 -o addr show primary dev $1 | awk '$3 == "inet" {print $4; exit}' | sed 's!/.*!!' -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]