簡體   English   中英

使用wget使用bash腳本下載文件

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM