How can I give a parameter to a subshell that has to be written in quotes?
I have a bash function that does something with data, lets call it check_data
:
check_data() {
echo "I check data. \"$1\" looks good."
}
When I call it, I have to quote the parameter, if it contains spaces:
check_data "Adam Brutus Caesar"
But now I want to check the results of a curl
request:
check_data $(curl --silent 'http://my.web.site.cool/myPath?arg1=Hey&arg2=Ho&arg3=$SESSIONID&arg4=Hi')
That of course only works if the result is a single word, otherwise only the first word would be checked. But when I quote the entire thing, ...
check_data "$(curl --silent 'http://my.web.site.cool/myPath?arg1=Hey&arg2=Ho&arg3=$SESSIONID&arg4=Hi')"
...arg3
is not given the content of $SESSIONID
but the String $SESSIONID
instead.
What am I missing here?
check_data $(curl ... 'http://...')
because the URL is in single quotes. The variable isn't expanded within single quotes – ilkkachu Aug 12 '21 at 07:44check_data "$(curl ... "http://...$SESSIONID..." )"
with double quotes inside and out. And escape with backslashes if you need literal dollar signs in the URL. – ilkkachu Aug 12 '21 at 07:47