不明确的重定向错误

不明确的重定向错误

我正在尝试使用此命令使 Bee 电影脚本在 100 个不同的文件中弹出。但当我运行它时,我不断收到此错误。我错过了什么吗?

错误:jacob{1..100}.txt:不明确的重定向

$ curl -s http://www.script-o-rama.com/movie_scripts/a1/bee-movie-script-transcript-seinfeld.html \
   > jacob{1..100}.txt

答案1

您可以使用tee。它从标准输入读取并写入标准输出和文件。

例子:

$ echo foo | tee {1..10}.txt
foo
$ ls
10.txt  1.txt  2.txt  3.txt  4.txt  5.txt  6.txt  7.txt  8.txt  9.txt
$ cat *
foo
foo
foo
foo
foo
foo
foo
foo
foo
foo

另请注意,使用该curl命令您将保存 HTML 页面而不是单独的脚本。您需要获取这些<pre>标签中的所有内容,但这是一个完全不同的问题。

答案2

您还可以将其分解为多个命令,因为当您第一次开始时更容易理解。例如:

下载文件
$ curl -s http://www.script-o-rama.com/movie_scripts/a1/bee-movie-script-transcript-seinfeld.html -O

上述操作将导致该文件被下载 - bee-movie-script-transcript-seinfeld.html.

将文件复制到 100 个副本
$ for i in {001..100}; do \
    cp bee-movie-script-transcript-seinfeld.html jacob${i}.txt; done

产生这些文件:

$ ls
bee-movie-script-transcript-seinfeld.html  jacob021.txt  jacob042.txt  jacob063.txt  jacob084.txt
jacob001.txt                               jacob022.txt  jacob043.txt  jacob064.txt  jacob085.txt
jacob002.txt                               jacob023.txt  jacob044.txt  jacob065.txt  jacob086.txt
jacob003.txt                               jacob024.txt  jacob045.txt  jacob066.txt  jacob087.txt
jacob004.txt                               jacob025.txt  jacob046.txt  jacob067.txt  jacob088.txt
jacob005.txt                               jacob026.txt  jacob047.txt  jacob068.txt  jacob089.txt
jacob006.txt                               jacob027.txt  jacob048.txt  jacob069.txt  jacob090.txt
jacob007.txt                               jacob028.txt  jacob049.txt  jacob070.txt  jacob091.txt
jacob008.txt                               jacob029.txt  jacob050.txt  jacob071.txt  jacob092.txt
jacob009.txt                               jacob030.txt  jacob051.txt  jacob072.txt  jacob093.txt
jacob010.txt                               jacob031.txt  jacob052.txt  jacob073.txt  jacob094.txt
jacob011.txt                               jacob032.txt  jacob053.txt  jacob074.txt  jacob095.txt
jacob012.txt                               jacob033.txt  jacob054.txt  jacob075.txt  jacob096.txt
jacob013.txt                               jacob034.txt  jacob055.txt  jacob076.txt  jacob097.txt
jacob014.txt                               jacob035.txt  jacob056.txt  jacob077.txt  jacob098.txt
jacob015.txt                               jacob036.txt  jacob057.txt  jacob078.txt  jacob099.txt
jacob016.txt                               jacob037.txt  jacob058.txt  jacob079.txt  jacob100.txt
jacob017.txt                               jacob038.txt  jacob059.txt  jacob080.txt
jacob018.txt                               jacob039.txt  jacob060.txt  jacob081.txt
jacob019.txt                               jacob040.txt  jacob061.txt  jacob082.txt
jacob020.txt                               jacob041.txt  jacob062.txt  jacob083.txt

然后您可以删除原始文件rm -f bee-movie-script-transcript-seinfeld.html.

相关内容