CURL命令在bash脚本中不起作用 [英] Curl command doesn't work in bash script

查看:73
本文介绍了CURL命令在bash脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to upload a JSON file into my noSQL database using a bash script, but it doesn't work and I don't understand why.

这是脚本:

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

当我执行命令行中给出的命令时,它仍然可以正常工作.

When I do the command given in my command line it works fine though.

这是什么错误?谢谢

推荐答案

不要将命令存储在变量中;如果您绝对必须具有可用于日志记录的功能,请将 arguments 放入数组中.

Don't store a command in a variable; if you absolutely must have something usable with logging, put the arguments in an array.

test='{"evaluation": "none"}'
args=( -XPUT localhost9200/test/evaluation/"$i" -d "$test" )
echo "curl ${args[*]}"
curl "${args[@]}"

这篇关于CURL命令在bash脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆