linux - 如何在 Linux bash shell 脚本的 curl 命令中使用变量来发送带有文件的 post 请求?

标签 linux shell curl post upload

例如。 我可以在终端中成功执行以下命令:

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

最佳答案

如果要变量扩展,请使用 "而不是 '

关于linux - 如何在 Linux bash shell 脚本的 curl 命令中使用变量来发送带有文件的 post 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44733378/

相关文章:

c - 当 2 个程序映射同一个文件时,mmap 如何工作

linux - 访问以单行而不是多行显示的变量

linux - 从 shell 脚本获取随机数并使用 snmpcommad(SNMP 协议(protocol))将其存储到文件中

php - Paypal 沙盒 CURL 执行 - "SSL connect error "

linux - 查看特定日期编辑的所有文件

regex - Pcregrep 包含文件扩展名错误

shell - 使用 netcat 逐行发送文本文件

php - 如何使用 PHP/cURL 代理请求并代理响应 header ?

PHP : Curl https xml result returns blank

java - 如何正确从视频内存加载/卸载纹理?