curl命令发起post数据的时候怎么传递变量

当我把变量传给curl命令-d参数内容里面的时候,报错如下:

ansible:type ansible$ account_id=172422
ansible:type ansible$ curl -s -m 2 -XPOST http://10.0.1.135:9200/mobilesdk_20180711/_search -d '{"size":0,"query":{"filtered":{"filter":{"and":{"filters":[{"term":{"account_id":$account_id}}]}}}}}';echo
{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[kx_c1GakR5S_uqwp0295RA][mobilesdk_20180711][0]: SearchParseException[[mobilesdk_20180711][0]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"filtered\":{\"filter\":{\"and\":{\"filters\":[{\"term\":{\"account_id\":$account_id}}]}}}}}]]]; nested: QueryParsingException[[mobilesdk_20180711] Failed to parse]; nested: JsonParseException[Unrecognized token '$account_id': was expecting ('true', 'false' or 'null')\n at [Source: [B@38605f89; line: 1, column: 94]]; }{[kx_c1GakR5S_uqwp0295RA][mobilesdk_20180711][1]: SearchParseException[[mobilesdk_20180711][1]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"filtered\":{\"filter\":{\"and\":{\"filters\":[{\"term\":{\"account_id\":$account_id}}]}}}}}]]]; nested: QueryParsingException[[mobilesdk_20180711] Failed to parse]; nested: JsonParseException[Unrecognized token '$account_id': was expecting ('true', 'false' or 'null')\n at [Source: [B@38605f89; line: 1, column: 94]]; }{[kx_c1GakR5S_uqwp0295RA][mobilesdk_20180711][2]: SearchParseException[[mobilesdk_20180711][2]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"filtered\":{\"filter\":{\"and\":{\"filters\":[{\"term\":{\"account_id\":$account_id}}]}}}}}]]]; nested: QueryParsingException[[mobilesdk_20180711] Failed to parse]; nested: JsonParseException[Unrecognized token '$account_id': was expecting ('true', 'false' or 'null')\n at [Source: [B@38605f89; line: 1, column: 94]]; }{[kx_c1GakR5S_uqwp0295RA][mobilesdk_20180711][3]: SearchParseException[[mobilesdk_20180711][3]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"filtered\":{\"filter\":{\"and\":{\"filters\":[{\"term\":{\"account_id\":$account_id}}]}}}}}]]]; nested: QueryParsingException[[mobilesdk_20180711] Failed to parse]; nested: JsonParseException[Unrecognized token '$account_id': was expecting ('true', 'false' or 'null')\n at [Source: [B@38605f89; line: 1, column: 94]]; }{[kx_c1GakR5S_uqwp0295RA][mobilesdk_20180711][4]: SearchParseException[[mobilesdk_20180711][4]: from[-1],size[0]: Parse Failure [Failed to parse source [{\"size\":0,\"query\":{\"filtered\":{\"filter\":{\"and\":{\"filters\":[{\"term\":{\"account_id\":$account_id}}]}}}}}]]]; nested: QueryParsingException[[mobilesdk_20180711] Failed to parse]; nested: JsonParseException[Unrecognized token '$account_id': was expecting ('true', 'false' or 'null')\n at [Source: [B@38605f89; line: 1, column: 94]]; }]","status":400}

请问怎么传递变量才可以?

已邀请:

空心菜 - 心向阳光,茁壮成长

如此传递你的参数account_id ,  "'"account_id"'"   或者 利用反斜杠进行转移,应该都是可以的。
参考:https://stackoverflow.com/questions/17029902/using-curl-post-with-variables-defined-in-bash-script-functions 

要回复问题请先登录注册