0
0
Bash Scriptingscripting~20 mins

Report generation script in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Report Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple report generation script
What is the output of this bash script that generates a report of file counts in the current directory?
Bash Scripting
#!/bin/bash
count=$(ls -1 | wc -l)
echo "Total files: $count"
ATotal files: 5
BTotal files: $(ls -1 | wc -l)
CTotal files: 0
DTotal files:
Attempts:
2 left
💡 Hint
The script counts files in the current directory and prints the total.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this report script
Which option contains the syntax error in this bash script that summarizes disk usage?
Bash Scripting
du -sh * > report.txt
echo "Report saved to report.txt"
A
du -sh * > report.txt
echo "Report saved to report.txt";
B
du -sh * > report.txt
echo "Report saved to report.txt""
C
du -sh * > report.txt
echo "Report saved to report.txt"
D
"txt.troper ot devas tropeR" ohce
txt.troper > * hs- ud
Attempts:
2 left
💡 Hint
Look for unmatched quotes or extra characters.
🔧 Debug
advanced
2:00remaining
Why does this report script fail to write output?
This script is supposed to write a list of running processes to a file named 'process_report.txt'. Why does it fail?
Bash Scripting
#!/bin/bash
ps aux > process_report.txt
cat process_report.txt
AThe script lacks execute permission.
BThe ps command is incorrect and produces no output.
CThe script runs correctly and outputs the process list.
DThe script runs but the output file is empty because of redirection order.
Attempts:
2 left
💡 Hint
Check if the commands are valid and redirection is correct.
🚀 Application
advanced
2:00remaining
Which script correctly appends a timestamp to a report file?
You want to add the current date and time at the end of 'report.txt'. Which script does this correctly?
Aecho "$(date)" >> report.txt
Becho "date" >> report.txt
Cdate >> report.txt
Decho date >> report.txt
Attempts:
2 left
💡 Hint
Use command substitution to get the current date output.
🧠 Conceptual
expert
2:00remaining
What is the number of lines in the report generated by this script?
This script lists all '.log' files and counts lines in each, saving output to 'log_report.txt'. How many lines will 'log_report.txt' contain if there are 3 '.log' files?
Bash Scripting
#!/bin/bash
wc -l *.log > log_report.txt
A0
B3
C1
D4
Attempts:
2 left
💡 Hint
The wc command outputs one line per file plus a total line.