The script uses cURL to download the RSS feed. You can view the format of the incoming data by logging in to your Gmail account and viewing https://mail.google.com/mail/feed/atom.
cURL reads the RSS feed with the user authentication provided by the -u user:pass argument. When you use -u user without the password cURL, it will interactively ask for the password.
- tr -d '\n': This removes the newline characters
- sed 's:</entry>:\n:g': This replaces every </entry> element with a newline, so each e-mail entry is delimited by a new line and, hence, mails can be parsed one-by-one.
The next block of script that needs to be executed as one single expression uses sed to extract the relevant fields:
sed 's/.*<title>\(.*\)<\/title.*<author><name>\([^<]*\)<\/name><email> \([^<]*\).*/Author: \2 [\3] \nSubject: \1\n/'
This script matches the title with the <title>\(.*\)<\/title regular expression, the sender name with the <author><name>\([^<]*\)<\/name> regular expression, and e-mail using <email>\([^<]*\). Sed uses back referencing to display the author, title, and subject of the e-mail into an easy to read format:
Author: \2 [\3] \nSubject: \1\n
\1 corresponds to the first substring match (title), \2 for the second substring match (name), and so on.
The SHOW_COUNT=5 variable is used to take the number of unread mail entries to be printed on the terminal.
head is used to display only the SHOW_COUNT*3 lines from the first line. SHOW_COUNT is multiplied by three in order to show three lines of output.