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
1

1 Answer 1

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\"}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.