为什么curl在命令行中成功,但在这个脚本中失败了?

为什么curl在命令行中成功,但在这个脚本中失败了?,curl,cygwin,Curl,Cygwin,我使用Cygwin运行CURL命令 $ curl http://URL/update.json --connect-timeout 10000 --max-time 10000 --data-binary @bars.json -H 'Content-type:application/json;charset=utf-8;X-Vendor-Email=myemaiL@gmail.com;' {"uploaded":true,"message":"Bars JSON received. A em

我使用Cygwin运行CURL命令

$ curl http://URL/update.json --connect-timeout 10000 --max-time 10000 --data-binary @bars.json -H 'Content-type:application/json;charset=utf-8;X-Vendor-Email=myemaiL@gmail.com;'
{"uploaded":true,"message":"Bars JSON received.  A email will be sent after processing has completed."}
正如您所看到的,这样做很好,并且可以很好地上传到远程服务器。我正试图通过将其放入脚本文件来自动化这个过程

我的脚本文件:

cd /cygdrive/x
curl http://URL/update.json --connect-timeout 10000 --max-time 10000 --data-binary @bars.json -H 'Content-type:application/json;charset=utf-8;X-Vendor-Email=EMAIL@gmail.com;
错误:

$ /bin/test.sh
: No such file or directorycygdrive/x
/bin/test.sh: line 2: unexpected EOF while looking for matching `''
/bin/test.sh: line 3: syntax error: unexpected end of file

您需要在命令末尾添加一个结束符

curlhttp://URL/update.json --连接超时10000—最大时间10000\
--data binary@bar.json\
-H'内容类型:应用程序/json;字符集=utf-8;X-Vendor-Email=EMAIL@gmail.com'

对不起,我没有按照你的建议退出。我的第一行应该是。。。cd/cygdrive/x'?还有。。。。供应商电子邮件=email@gmail.com''???这是传递给
-H
选项的参数。它有一个单引号字符来打开(
'Content-type…
),但您在结尾缺少结束字符。对于后代,我在将用户输入作为参数字符串从Ruby脚本传递到bash脚本(特别是用户名和密码)时遇到了同样的问题。碰巧我发送的密码包含一个撇号
。在本例中,解决方案是在将用户输入发送到bash脚本之前引用用户输入。