0

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?

Bowi
  • 101
  • 1
  • you should already get that problem with `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:44
  • See: [What is the difference between the “…”, '…', $'…', and $“…” quotes in the shell?](https://unix.stackexchange.com/questions/503013/what-is-the-difference-between-the-and-quotes-in-th) – ilkkachu Aug 12 '21 at 07:45
  • 1
    `check_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
  • Thank you very much @ilkkachu, double quotes inside and outside do the trick! I will read your link as well nonetheless. :-) – Bowi Aug 12 '21 at 07:57

0 Answers0