0
0
Bash Scriptingscripting~20 mins

File download automation in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Download Automation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this wget command?
You run this command in a terminal:
wget -q --show-progress https://example.com/file.txt -O downloaded.txt && echo "Done"

What will be printed on the terminal?
Bash Scripting
wget -q --show-progress https://example.com/file.txt -O downloaded.txt && echo "Done"
ANo output at all
BProgress bar showing download progress
CDone
DError message about missing file
Attempts:
2 left
💡 Hint
The -q option means quiet, but --show-progress overrides some quietness.
📝 Syntax
intermediate
2:00remaining
Which script correctly downloads multiple files in a loop?
You want to download files from URLs stored in a file named urls.txt, one URL per line. Which script snippet correctly downloads each file using curl?
Afor url in $(cat urls.txt); do curl -O "$url"; done
Bwhile read url; do curl -O "$url"; done < urls.txt
Ccat urls.txt | for url in $urls.txt; do curl -O "$url"; done
Dfor url in urls.txt; do curl -O "$url"; done
Attempts:
2 left
💡 Hint
Think about how to read lines safely from a file in bash.
🔧 Debug
advanced
2:30remaining
Why does this script fail to download files correctly?
Consider this script:
urls=("http://site.com/file 1.txt" "http://site.com/file2.txt")
for url in "${urls[@]}"; do
  curl -O "$url"
done

It fails to download the first file. What is the problem?
Bash Scripting
urls=("http://site.com/file 1.txt" "http://site.com/file2.txt")
for url in "${urls[@]}"; do
  curl -O "$url"
done
AThe space in the URL is not encoded, causing curl to fail.
BThe array syntax is wrong; it should use single quotes.
CThe for loop syntax is invalid; it needs a semicolon after do.
Dcurl cannot handle URLs with numbers.
Attempts:
2 left
💡 Hint
Spaces in URLs must be encoded as %20.
🚀 Application
advanced
2:00remaining
How to automate retrying downloads on failure?
You want a bash script that tries to download a file with curl up to 3 times if it fails. Which snippet achieves this?
Acurl -O http://example.com/file.txt; if [ $? -ne 0 ]; then curl -O http://example.com/file.txt; fi
Bcurl -O http://example.com/file.txt || curl -O http://example.com/file.txt || curl -O http://example.com/file.txt
Cfor i in {1..3}; do curl -O http://example.com/file.txt && break; done
Dwhile curl -O http://example.com/file.txt; do break; done
Attempts:
2 left
💡 Hint
Use a loop with a break on success.
🧠 Conceptual
expert
3:00remaining
What is the best way to download files securely in a script?
You want to automate file downloads in bash but ensure the files are not tampered with. Which approach is best?
ADownload files and trust the source without verification.
BUse wget with --no-check-certificate to avoid SSL errors.
CDownload files only over HTTP to avoid SSL overhead.
DDownload files with curl and then verify their SHA256 checksum against a trusted value.
Attempts:
2 left
💡 Hint
Think about verifying file integrity after download.