使用wget使用bash脚本下载文件

use*_*255 5 bash loops wget cat

我一直在尝试创建一个简单的脚本,它将从.txt文件中下载文件列表,然后使用循环它将读取.txt需要在另一个文件的帮助下下载的文件. txt文件在将要下载的文件的地址中.但我的问题是我不知道该怎么做.我尝试了很多次,但我总是失败.

file.txt
1.jpg
2.jpg
3.jpg
4.mp3
5.mp4
Run Code Online (Sandbox Code Playgroud)

=====================================

url.txt
url = https://google.com.ph/
Run Code Online (Sandbox Code Playgroud)

=====================================

download.sh
#!/bin/sh
url=$(awk -F = '{print $2}' url.txt)
for i in $(cat file.txt);
do 
wget $url
done
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助.

jay*_*ngh 7

除了R Sahu在答案中指出的明显问题,你可以避免:

  • 使用awk解析您的url.txt文件.
  • 使用for $(cat file.txt)通过file.txt的文件进行迭代.

这是你可以做的:

#!/bin/bash

# Create an array files that contains list of filenames
files=($(< file.txt))

# Read through the url.txt file and execute wget command for every filename
while IFS='=| ' read -r param uri; do 
    for file in "${files[@]}"; do 
        wget "${uri}${file}"
    done
done < url.txt
Run Code Online (Sandbox Code Playgroud)