[英]How to use variable in curl command in Linux bash shell script to send post request with file?
例如。 我可以在终端中成功执行以下命令:
curl -sX POST -F 'file=@/tmp/test.tgz' -F 'fileName=test.tgz' http://localhost:8080/upload
但是,如果我在bash shell脚本中用变量替换文件路径str“ /tmp/test.tgz”,那么它将无法正常工作,请您帮我解决一下吗?
curl -sX POST -F 'file=@$myfile' -F 'fileName=test.tgz' http://localhost:8080/upload
如果要变量扩展,请使用“而不是”
ff="'file=$myfile'"
fname="'fileName=test.tgz'"
eval curl -sX POST -F $ff $fname http://localhost:8080/upload
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.