Reputation: 334
I am attempting to grab a specific field from a curl request. It works perfectly fine via the shell, but as soon as I try to assign a variable it stops working.
This is the stand-alone command.
curl --silent 'http://alerts.weather.gov/cap/wwaatmget.php?x=MNC131&y=0' | grep -E ' <title>' | awk -F '[<>]' '{print $3}'
This is the small bit from the script. It echos a blank variable.
weatheralert=$(curl --silent 'http://alerts.weather.gov/cap/wwaatmget.php?x=MNC131&y=0' | grep -E ' <title>' | awk -F '[<>]' '{print $3}')
echo "Current Weather Alert: $weatheralert"
Upvotes: 0
Views: 216
Reputation: 174706
Note that there is a tab
character exists before <title>
tag not 3 or 4 whitespace. So copy paste a tab character or use grep -P '\t<title>'
command.
$ weatheralert=$(curl --silent 'http://alerts.weather.gov/cap/wwaatmget.php?x=MNC131&y=0' | grep -P '\t<title>'|awk -F '[<>]' '{print $3}')
$ echo "Current Weather Alert: $weatheralert"
Current Weather Alert: There are no active watches, warnings or advisories
Upvotes: 1