Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用curl下载带有填充零的文件_Bash_Curl - Fatal编程技术网

Bash 使用curl下载带有填充零的文件

Bash 使用curl下载带有填充零的文件,bash,curl,Bash,Curl,嗨,我有多个文件的例子 01.pdf 02.pdf 等 在一个bash脚本中,我创建了一个for循环并使用curl,但是它尝试下载 1.pdf 2.pdf 等 有什么解决方法吗?您可以使用printf填充文件名: urlbase='http://myhost.com/path/files' for i in {1..10}; do fname=$(printf "%02d.pdf\n" $i) curl -o $fname "$urlbase/$fname" done 我理解这

嗨,我有多个文件的例子 01.pdf 02.pdf 等

在一个bash脚本中,我创建了一个for循环并使用curl,但是它尝试下载 1.pdf 2.pdf 等


有什么解决方法吗?

您可以使用
printf
填充文件名:

urlbase='http://myhost.com/path/files'
for i in {1..10}; do
    fname=$(printf "%02d.pdf\n" $i)
    curl -o $fname "$urlbase/$fname"
done

我理解这一点,但如何使用curl命令实现它呢?您还可以使用
printf-vfname
为变量赋值。