This is what I got reading here and there:
Code: Select all
#!/bin/bash
opentag=\<title\>
closetag=\</title\>
#get Gmail rss atom
rss=$(curl -su USER:PASS https://mail.google.com/mail/feed/atom)
#find <title> lines
lines=$(echo "$rss" | grep "$opentag")
#line number
lnum=0
#iterate each line
echo "$lines" | while read -r line
do
#strip open tag
line=${line#*$opentag}
#strip close tag
line=${line%$closetag*}
#jump first occourence since it's whole XML title
if (( lnum )); then
echo "$lnum $line"
fi
(( lnum ++ ))
done
#show numbero of messagges
echo "$lnum messages"
The only solution I found is to save variables on files and avoid piping like this:
Code: Select all
#!/bin/bash
opentag=\<title\>
closetag=\</title\>
#get Gmail rss atom on temp file
wget curl -su USER:PASS https://mail.google.com/mail/feed/atom > /tmp/gmailrss
#find <title> lines
grep "$opentag" /tmp/gmailrss > /tmp/gmaillines
#line number
lnum=0
#iterate each line
while read -r line
do
#strip open tag
line=${line#*$opentag}
#strip close tag
line=${line%$closetag*}
#jump first occourence since it's whole XML title
if (( lnum )); then
echo "$lnum $line"
fi
(( lnum ++ ))
done < /tmp/gmaillines
echo "$lnum messages"
I hope there's a better way than piping to pass read and grep the content of my variables so a new subshell is not started and I can use my lnum counter.
I know this is a bash script forum related topic but I know there are a lot of good shell script writers here so why not?