Curl 命令在 bash 脚本中不起作用

2023-11-30

我正在尝试使用 bash 脚本将 JSON 文件上传到我的 noSQL 数据库中,但它不起作用,我不明白为什么。

这是脚本:

test='{"evaluation": "none"}'
test="'$test'"
command="curl -XPUT localhost:9200/test/evaluation/$i -d $test"
echo "$command"
$command 

这是错误:

curl -XPUT localhost:9200/test/evaluation/0 -d '{"evaluation": "none"}'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (3) [globbing] unmatched close brace/bracket in column 7

当我执行命令行中给出的命令时,它工作正常。

这里有什么错误?谢谢


不要将命令存储在变量中;如果你绝对必须有一些可用于日志记录的东西,请将论点在一个数组中。

test='{"evaluation": "none"}'
args=( -XPUT localhost9200/test/evaluation/"$i" -d "$test" )
echo "curl ${args[*]}"
curl "${args[@]}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Curl 命令在 bash 脚本中不起作用 的相关文章