我在Bash上遇到以下问题:如果我将命令作为原始字符串提供,但是如果我将该字符串存储在变量中,然后尝试执行(评估)该变量,即 data参数,则运行命令有效无法识别:
#!/usr/bin/env bash
# this works
out=$(curl -s http://localhost:5000/sfm -d '{"numero_processo":"0000002-78.2014.5.20.0007"}' -H 'Content-Type:application/json' -X POST)
# but if i store it in a variable then it doesn't work (when I
# look at the request on a flask backend, the data parameter is empty)
# note that i've escaped the double quotes
command="curl -s http://localhost:5000/sfm -d '{\"param\":\"8.2014.5.20.0007\"}' -H 'Content-Type:application/json' -X POST"
out=$($command)
这两种方法不应该完全相同吗?这是怎么回事?