![如何使用 wget bash 脚本一次下载一个文件](https://linux22.com/image/174950/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20wget%20bash%20%E8%84%9A%E6%9C%AC%E4%B8%80%E6%AC%A1%E4%B8%8B%E8%BD%BD%E4%B8%80%E4%B8%AA%E6%96%87%E4%BB%B6.png)
所以我制作了这个 bash 脚本来从网站下载多个文件,我想在后台下载这些文件,因此“-b 标志”。
脚本:list.sh
wget -b -O filename.jpg www.example.com/image1.jpg
wget -b -O filename2.jpg www.example.com/image2.jpg
wget -b -O filename3.jpg www.example.com/image4.jpg
如何一次执行一个命令?我想一次下载一个文件,然后在第一个文件完成后,我想下载第二个文件等。
当我运行时./list.sh
,它开始立即下载所有文件。
答案1
如果我理解正确的话,你想运行所有的后台脚本,所以:
#!/bin/bash
wget -O filename.jpg www.example.com/image1.jpg
wget -O filename2.jpg www.example.com/image2.jpg
wget -O filename3.jpg www.example.com/image4.jpg
然后:
$ screen
$ ./script
现在您可以断开与 Linux 计算机的连接,然后返回并检索会话:
$ screen -r
apt-cache show screen
[...]
Description-en: terminal multiplexer with VT100/ANSI terminal emulation
GNU Screen is a terminal multiplexer that runs several separate "screens" on
a single physical character-based terminal. Each virtual terminal emulates a
DEC VT100 plus several ANSI X3.64 and ISO 2022 functions. Screen sessions
can be detached and resumed later on a different terminal.
.
Screen also supports a whole slew of other features, including configurable
input and output translation, serial port support, configurable logging,
and multi-user support.