[英]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.