Score:0

Is it feasible to send a post in the form of some variables rather than raw string?

th flag

This code sends a post request to a specified url

urlStr='http://coliru.stacked-crooked.com/compile'
curl $urlStr -d '{"cmd": "g++-4.8 main.cpp && ./a.out", "src": "#include <iostream>\nint main(){    std::cout << \"Hello World!\" << std::endl;}"}'

where the url is given via the $urlStr variable

I'm trying to replace the other parts with variables

codeStr='#include <iostream>\nint main() {\n  std::cout << \"Hello World!\" << std::endl;\n}'
cmdStr='g++ main.cpp && ./a.out'
curl $urlStr -d '{"cmd": $cmdStr, "src": $codeStr}'

and I got an error

765: unexpected token at '{"cmd": $cmdStr, "src": $codeStr}'

How do I make it work?

bac0n avatar
cn flag
`"{\"cmd\": \"$cmdStr\", \"src\": \"$codeStr\"}"`, think you want to expand your variables.
hr flag
... see also [Bash variable in 2 quotes](https://askubuntu.com/questions/1385884/bash-variable-in-2-quotes)
bac0n avatar
cn flag
Does this answer your question? [Bash variable in 2 quotes](https://askubuntu.com/questions/1385884/bash-variable-in-2-quotes)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.