If you use single quotes ('like this'
) in bash, you get a literal string with no variable expansion. That is, compare:
$ echo '$DISPLAY'
$DISPLAY
With:
$ echo "$DISPLAY"
:0
This is exactly the same situation as in your curl
command line, where you have:
'{ "author": "icingaadmin", "comment": " Working on it.", "notify": true, "filter": "host.name == {\"$1\} && service.name == {\"$2\}"" }'''
There's actuall a number of quoting problems there starting with the '''
at the end, and including the ""
just before the final }
. If you want those variables to expand you will need to move them outside of your single quotes. You can do this:
'"host.name == {"'"$1"'"} && ...'
In this case, the "$1"
is outside of the single quotation marks. Alternatively, you can do this:
"\"host.name == {\"$1\"} ** ..."
Here we're just using double quotes on the outside, so variable expansion works normally, but we have to escape every literal "
inside the string.
Using the first option, the final argument to -d
would look like something like this ("something" because I'm not familiar with icinga):
'{ "author": "icingaadmin", "comment": " Working on it.", "notify": true, "filter": "host.name == {"'"$1"'"} && service.name == {"'"$2"'"}}'
If $1
is foo
and $2
is bar
, this gives you:
{ "author": "icingaadmin", "comment": " Working on it.", "notify": true, "filter": "host.name == {"foo"} && service.name == {"bar"}}