Bird
Raised Fist0
Bash Scriptingscripting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of automating file downloads in bash scripting?
easy
A. To slow down the internet speed
B. To make files larger
C. To save time and reduce manual errors
D. To delete files automatically

Solution

  1. Step 1: Understand automation benefits

    Automating repetitive tasks like file downloads saves time and reduces mistakes.
  2. Step 2: Identify the correct purpose

    The main goal is efficiency and accuracy, not file size or deletion.
  3. Final Answer:

    To save time and reduce manual errors -> Option C
  4. Quick Check:

    Automation = Save time & reduce errors [OK]
Hint: Automation means doing tasks faster and safer [OK]
Common Mistakes:
  • Thinking automation changes file size
  • Confusing automation with file deletion
  • Assuming automation slows internet
2. Which of the following is the correct syntax to download a file using wget in bash?
easy
A. curl -download http://example.com/file.txt
B. download http://example.com/file.txt
C. fetch http://example.com/file.txt
D. wget http://example.com/file.txt

Solution

  1. Step 1: Recall wget command syntax

    The basic wget command to download a file is 'wget URL'.
  2. Step 2: Compare options

    Only wget http://example.com/file.txt uses the correct wget syntax; others use invalid commands.
  3. Final Answer:

    wget http://example.com/file.txt -> Option D
  4. Quick Check:

    wget URL = correct syntax [OK]
Hint: Use 'wget URL' to download files simply [OK]
Common Mistakes:
  • Using non-existent commands like 'download' or 'fetch'
  • Mixing curl options with wget
  • Forgetting to specify the URL
3. What will be the output of this bash command?
curl -O https://example.com/sample.txt
ls | grep sample.txt
medium
A. sample.txt
B. No output
C. curl: command not found
D. Error: file not found

Solution

  1. Step 1: Understand curl -O behavior

    The command downloads 'sample.txt' to the current directory.
  2. Step 2: Check the ls and grep output

    Listing files and filtering for 'sample.txt' will show the filename if download succeeded.
  3. Final Answer:

    sample.txt -> Option A
  4. Quick Check:

    curl -O downloads file, ls | grep shows filename [OK]
Hint: curl -O saves file; grep finds it in list [OK]
Common Mistakes:
  • Assuming curl prints file content
  • Expecting no output after download
  • Confusing curl errors with normal output
4. Identify the error in this script snippet for downloading a file:
curl -o https://example.com/data.csv
medium
A. URL is incorrect
B. Missing filename after -o option
C. curl cannot download CSV files
D. No error, script is correct

Solution

  1. Step 1: Check curl -o usage

    The '-o' option requires a filename to save the download.
  2. Step 2: Analyze the command

    The command provides URL but no filename after '-o', causing error.
  3. Final Answer:

    Missing filename after -o option -> Option B
  4. Quick Check:

    curl -o needs filename [OK]
Hint: Always give filename after curl -o [OK]
Common Mistakes:
  • Forgetting filename after -o
  • Thinking URL is wrong format
  • Believing curl can't download certain file types
5. You want to automate downloading multiple files listed in a text file named urls.txt. Which bash script snippet correctly downloads each file using wget?
hard
A. while read url; do wget "$url"; done < urls.txt
B. for url in urls.txt; do wget $url; done
C. wget -i urls.txt -O output.log
D. cat urls.txt | wget

Solution

  1. Step 1: Understand reading lines from file

    The 'while read url; do ... done < urls.txt' reads each line as a URL.
  2. Step 2: Check wget usage inside loop

    Using wget "$url" downloads each URL correctly.
  3. Step 3: Analyze other options

    'for url in urls.txt; do wget $url; done' treats filename as URL, 'wget -i urls.txt -O output.log' misuses -O option causing all files to overwrite as 'output.log', 'cat urls.txt | wget' pipes incorrectly.
  4. Final Answer:

    while read url; do wget "$url"; done < urls.txt -> Option A
  5. Quick Check:

    Loop reading lines + wget = correct [OK]
Hint: Use while read loop to process URLs line by line [OK]
Common Mistakes:
  • Using for loop directly on filename
  • Misusing wget options
  • Piping file content directly to wget
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard