[英]curl command not accepting input from file
我正在尝试运行curl命令,例如:
curl -Sks -XPOST https://localhost:9999/some/local/service -d 'some text arguments'
以上工作正常。 但是,当我放置
'some text arguments'
在文件中,并按以下方式调用命令:
curl -Sks -XPOST https://localhost:9999/some/local/service -d `cat file_with_args`
我从服务中获得了很多例外。 有人知道为什么是这样吗?
谢谢!
如果文件包含'some text arguments'
,则您的命令与此等效:
curl -Sks -XPOST https://localhost:9999/some/local/service -d \'some text arguments\'
—也就是说,它将'some
, text
和arguments'
作为三个单独的参数传递给curl
。
相反,您应该在文件中仅放置some text arguments
(不使用单引号),然后运行以下命令:
curl -Sks -XPOST https://localhost:9999/some/local/service -d "`cat file_with_args`"
(将`cat file_with_args`
部分用双引号引起来,以使生成的some text arguments
不会拆分为单独的参数)。
顺便说一句,我建议写$(...)
而不是`...`
,因为它通常更健壮(尽管在您的特定命令中没有任何作用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.