BASH script help with MAC (sed problem?)

Working on transmitting to an ethernet connected arduino my unread email count…

I came across this example.

Well, the bash script doesn’t work on my mac’s OS… my Mac doesn’t seem to like this:

MAILCOUNTER=`curl -u $USERID:$PASSWORD --silent "https://mail.google.com/mail/feed/atom" | sed -n 's|<fullcount>\(.*\)</fullcount>|\1|p'`

anyone have a suggestion to get it to work:

#!/bin/bash
#SCRIPT_NAME="Arduino Gmail Checker"
#SCRIPT_VERSION="0.1"
#figlet $SCRIPT_NAME $SCRIPT_VERSION
#########################################################################################
# Description: Check Gmail for unread email and switch RGB LED on Arduino in accordance #
# Dependencies: sed, curl,                                                              #
# Author: Virtualmix                                                                    #
# http://blog.trollmaker.com/article10/arduino-led-notification-for-gmail-on-linux      #
# License: CC BY                                                                        #
#########################################################################################
# Enter Gmail username and password below (Warning: Unsafe storage):
USERID=youremail@gmail.com
PASSWORD=yoursecretpassword
# Enter number of seconds between email verification:
WAIT=10
#########################################################################################

# Loop to check for new mail every X minutes:
while [ "1" -eq "1" ]; do

    # Command line to fetch the number of unread emails:
    MAILCOUNTER=`curl -u $USERID:$PASSWORD --silent "https://mail.google.com/mail/feed/atom" | sed -n 's|<fullcount>\(.*\)</fullcount>|\1|p'`

    if [[ "$MAILCOUNTER" = "" ]]; then
        echo "ERROR: The program coulndn't fetch the account for user \"$USERID\"."
        echo "- Are you connected to the Internet?"
        echo -e "- Is the userid and password correct for \"$USERID\"?\n"
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount=-1&

    elif [[ "$MAILCOUNTER" -eq "0" ]]; then
        echo "* There is 0 new email for user $USERID."
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount=0&
        
    elif [[ "$MAILCOUNTER" -gt "0" ]]; then
        echo "* There is $MAILCOUNTER new email for user $USERID."
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount=$MAILCOUNTER&
    fi

    echo "* Waiting $WAIT seconds before checking for emails again."
    echo "* (^C to quit the program)"
    sleep $WAIT

done

BASH script to get email count and send to arduino via http get:

WAIT=120
while [ "1" -eq "1" ]; do

    # Command line to fetch the number of unread emails:
    MAILCOUNTER=`curl -u USERNAME:PASSWORD --silent "https://mail.google.com/mail/feed/atom" \ | xmllint --format - \ | sed -n 's#<fullcount>\(.*\)</fullcount>#\1#p'`
    if [[ "$MAILCOUNTER" = "" ]]; then
        echo "ERROR: The program coulndn't fetch the account for user \"$USERID\"."
        echo "- Are you connected to the Internet?"
        echo -e "- Is the userid and password correct for \"$USERID\"?\n"
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount=-1\&

    elif [[ "$MAILCOUNTER" -eq "0" ]]; then
        echo "* There is 0 new email for user $USERID."
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount=0&
        
    elif [[ "$MAILCOUNTER" -gt "0" ]]; then
        echo "* There is $MAILCOUNTER new email for user $USERID."
        curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET 192.168.1.50/?emailCount="$MAILCOUNTER"&
    fi

    echo "* Waiting $WAIT seconds before checking for emails again."
    echo "* (^C to quit the program)"
    sleep $WAIT
#set +xv
done