在选项-F

时间:2019-03-01 08:31:26

标签: bash curl

我正在寻找一种在Debian 9.3的bash shell中的“ file = @ / my / file / path / from / variable / tshootinginfo.txt” 中使用变量的方法。

我的CURL请求:

curl -s -k -D- -u ${user}:${password} -X POST -H "X-Atlassian-Token: nocheck" -F "file=@/my/file/path/from/variable/tshootinginfo.txt" ${jira_subtask}/attachments

我已经尝试了几次不同的逃生尝试,但是进展不大。 越狱尝试:

location_var="/my/file/path/from/variable/tshootinginfo.txt"

-F "file=\"@$location_var\""
-F "file=@\"$location_var\""
-F "file=@\'$location_var\'"
-F "file=@\${location_var}"

1 个答案:

答案 0 :(得分:1)

-F file=@...之后的参数只是一个字符串。

curl -s -k -D- -u "${user}:${password}" \
    -X POST -H "X-Atlassian-Token: nocheck" \
    -F "file=@$my_location_var" \
    "${jira_subtask}/attachments"

如果愿意,可以在变量名的两边加上大括号,但是在任何情况下都没有必要。不过请注意quote your variables properly,