tsh*_*tsh 1 curl variable-substitution variable
我需要在 curl 中包含变量
for fname in "assets/*.drx"; do
echo $fname
curl -F file=@"$fname" "http://someurl.com/"
echo $fnamename
done
Run Code Online (Sandbox Code Playgroud)
结果:
assets/5baa5caa414f1d7786e86d03_1545903119.11.drx
curl: (26) couldn't open file "assets/*.drx"
assets/5baa5caa414f1d7786e86d03_1545903119.11.drx
Run Code Online (Sandbox Code Playgroud)
似乎 curl 使用 glob 表达式,但 echo 使用实际文件名。为什么 curl 的行为是这样的?为什么 echo 会看到实际变量以及如何在 curl 中使用文件名?
您引用了*通配符,以防止 shell 对其进行扩展。
for fname in assets/*.drx; do
printf '%s\n' "$fname"
curl -F file=@"$fname" "http://someurl.com/"
done
Run Code Online (Sandbox Code Playgroud)
该fname变量被分配了文字文本assets/*.drx。当你用它加引号的echo,外壳尽职尽责地扩展它。