I'm trying to make a small shell program to get me fortune cookie quotes. When I run it in my terminal it (almost) works fine
curl -s http://www.fortunecookiemessage.com | grep -oP '(<div class=\"quote\").*(</div>)' | sed 's/.*link\">\(.*\)<\/a>.*/\1/'
But when I tried putting the same into my bash script (run.sh) like this
sentence=$(curl -s http://www.fortunecookiemessage.com | grep -oP '(<div class=\"quote\").*(</div>)' | sed 's/.*link\">\(.*\)<\/a>.*/\1/')
it gave me an error as follows
bash-3.2# sh run.sh
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
I need help to resolve this. Also, sometimes the quote which gets extracted comes in the format <p>QUOTE</p>. This isn't all the time but sometimes only. I'm wondering what I must change in the regular expression in the sed command to cut out the <p></p> tags IF it occurs.
My output with set -x
bash-3.2# sh run.sh
++ curl -s http://www.fortunecookiemessage.com
++ grep -oP '(<div class=\"quote\").*(</div>)'
++ sed 's/.*link\">\(.*\)<\/a>.*/\1/'
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
(23) Failed writing body
+ sentence=
+ echo