[英]download files using bash script using wget
我一直在尝试创建一个简单的脚本,它将从.txt文件中下载一个文件列表,然后使用一个循环它将读取.txt需要在另一个分离的帮助下下载哪些文件。 txt文件在将要下载的文件的地址中。 但我的问题是我不知道该怎么做。 我尝试了很多次,但我总是失败。
file.txt
1.jpg
2.jpg
3.jpg
4.mp3
5.mp4
=====================================
url.txt
url = https://google.com.ph/
=====================================
download.sh
#!/bin/sh
url=$(awk -F = '{print $2}' url.txt)
for i in $(cat file.txt);
do
wget $url
done
非常感谢您的帮助。
除了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
代替
wget $url
尝试
wget "${url}${i}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.