Issue
I have a simple bash script that uses REST API for one application. For that, I need to run this command:
curl --location --request DELETE 'https://example.com/jasperserver/rest_v2/resources/Reports/$var'
Please help me to figure out how exactly variable can be passed to URL. I could pass data using -d "$var", or username with password, but not URL.
Solution
Just use double quotes. It will do the variable expansion -
curl --location --request DELETE "https://example.com/jasperserver/rest_v2/resources/Reports/$var"
Single quote keeps it's content as it is (from GNU docs) -
Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash
So your url is interpreted as
https://example.com/jasperserver/rest_v2/resources/Reports/$var
Double quotes is similar to single quotes except it cares for special character like $
(from GNU doc) -
Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’
Answered By - Syed Nakib Hossain