0
curl -X DELETE -d '{"ruleid": "${value}"}' 'http://192.168.0.12:8080/wm/firewall/rules/json'

This command can't run correctly. I don't know how to handle this value parameter. How to use the quotes?

#! /bin/bash
#  delete a firewall rule
value=x
if [ $1 != "" ]; then
value=$1
echo "$value"
curl -X DELETE -d '{"ruleid": "${value}"}'     http://192.168.0.12:8080/wm/firewall/rules/json
exit 0

else
    echo "no parameter "
    exit 0
fi
codeforester
  • 39,467
  • 16
  • 112
  • 140
Jimi
  • 11
  • 3
  • 2
    A helpful post here: [Difference between single and double quotes in Bash](http://stackoverflow.com/a/42082956/6862601) – codeforester Mar 24 '17 at 16:17

1 Answers1

3

This example is a nightmare of quoting, but here is the correct syntax:

  curl -X DELETE -d '{"ruleid": "'"$value"'"}'
#                                ||      |
# here we close the single quote +|      + the same applies for closing 
#                                 |
#      here we open double quotes +                           

You should enclose everything in single quotes, except for the variable that is double quoted.

An alternative would be

curl -X DELETE -d "{\"ruleid\": \"$value\"}"
user000001
  • 32,226
  • 12
  • 81
  • 108