Fab*_*bby 0 bash curl brace-expansion
我想通过以下方式下载一堆编号的文本文件:
curl https://www.grc.com/sn/sn-{472..807}.txt > sn-{472..807}.txt
Run Code Online (Sandbox Code Playgroud)
但这给了我:
bash: sn-{472..807}.txt: 不明确的重定向
所以我最终做了一个:
for iEpisode in {472..807}; do
curl https://www.grc.com/sn/sn-"$iEpisode.txt" > sn-"$iEpisode.txt";
if [[ $? -eq 1 ]]; then exit; fi;
done
Run Code Online (Sandbox Code Playgroud)
问题是:有没有办法做一个简单 curl 的双支架扩展?
(因为它对我来说看起来并不模棱两可,而且我的 Google-fu 一无所获) :/
这是模棱两可的,因为您正在尝试重定向到多个文件。你的壳会选择哪个?
一般来说,您将需要for循环,但您可以使用 Curl
curl --remote-name-all https://www.grc.com/sn/sn-{472..807}.txt
Run Code Online (Sandbox Code Playgroud)
该选项就像-O(参见手册页),
-O, --remote-name
将输出写入本地文件,命名为我们得到的远程文件。(仅使用远程文件的文件部分,路径被截断。)
但适用于每一个论点。
Curl 也理解类似 shell 的范围:
curl -O 'https://www.grc.com/sn/sn-[472-807].txt'
Run Code Online (Sandbox Code Playgroud)