In my bash script, I store a curl command in a variable:
MYCOMMAND="curl -n https://gerrit.myCompany.com/a/changes/?q=project:xyzProject+branch:master+ownerin:abcGroup\"&\"n=20"
Note that the query needs to be appended with "&"n=someNumber in order to limit the number of results returned by the gerrit server.
Now if I echo my variable everything seems fine:
echo "my command is " $MYCOMMAND
my command is curl -n https://gerrit.myCompany.com/a/changes/?q=project:xyzProject+branch:master+ownerin:abcGroup"&"n=20
Infact if I copy this output and directly paste it in the script OR give it on the command prompt it works very well and I get my required gerrit query output
But if I run it directly from the variable it throws error "--"n" is not a valid option
$MYCOMMAND
"--"n" is not a valid option
I am very much puzzled by this behavior. Can someone help?