Reputation: 157
Hi i am trying to use curl in shell script as shown below but i am not able to substitute the variable $line in the CURL . please suggest
while read line
do
echo "allowing mac $line"
curl -X POST -d '{"src-mac": "$line"}' http://localhost:8080/wm/firewall/rules/json
curl -X POST -d '{"dst-mac": "$line"}' http://localhost:8080/wm/firewall/rules/json
done < /home/floodlight/allowedmacs
Upvotes: 3
Views: 2301
Reputation: 95375
No variable substitution in single quotes. Switch to double around the expansion, like this:
curl -X POST -d '{"src-mac": "'"$line"'"}' http://localhost:8080/wm/firewall/rules/json
curl -X POST -d '{"dst-mac": "'"$line"'"}' http://localhost:8080/wm/firewall/rules/json
Or you could use double-quotes around the whole thing and escape the inner ones:
curl -X POST -d "{\"src-mac\": \"$line\"}" http://localhost:8080/wm/firewall/rules/json
curl -X POST -d "{\"dst-mac\": \"$line\"}" http://localhost:8080/wm/firewall/rules/json
Either way, can't be inside single quotes when you get to $line
if you want it expanded.
Upvotes: 7