ダウンロードしたいさまざまな画像があり、利用可能なリンクがあるとします。
一つ一つ入力したくない
wget https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
wget https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
これを実現するにはどうすればよいですか? これらのリンクを .txt ファイルに保存し、for ループを使用するのは正しい方法ではないと読みました。
答え1
次のようなファイルに URL がある場合:
https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
そうすれば走れる
wget --input-file=file
@の説明に従って画像をダウンロードするクサラナンダ。
答え2
すべてを同じスクリプト内に保持したい場合は、--input-file
/-i
オプションで以下も読み取ることができます。stdin
wget -i - << EOF
https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
EOF