Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the current date in the report header.
Bash Scripting
echo "Report generated on: $(date [1])"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-d' which expects a date string, not a format.
Using '%H:%M:%S' without '+' which is invalid.
Using '-u' which changes timezone, not format.
✗ Incorrect
The '+%Y-%m-%d' option formats the date command to show the year-month-day format.
2fill in blank
mediumComplete the code to count the number of lines in the file 'data.txt'.
Bash Scripting
line_count=$(wc -l [1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra flags like '-w' or '-c' which count words or bytes.
Putting the filename before the option '-l'.
✗ Incorrect
The 'wc -l' command counts lines, and the filename 'data.txt' must be given as argument.
3fill in blank
hardFix the error in the script to append the summary to 'report.txt'.
Bash Scripting
echo "Summary: Total lines = $line_count" [1] report.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which overwrites the file.
Using '<' which is input redirection.
Using '|' which pipes output to another command.
✗ Incorrect
The '>>' operator appends output to the file without overwriting it.
4fill in blank
hardFill both blanks to create a loop that processes each line in 'data.txt'.
Bash Scripting
while IFS=[1] read -r [2]; do echo "Processing: $[2]" done < data.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting IFS to a space which splits words, not lines.
Using 'word' which is misleading for line reading.
✗ Incorrect
Setting IFS to empty string preserves leading/trailing spaces; 'line' is a common variable name for each line.
5fill in blank
hardFill all three blanks to create a dictionary-like summary of word counts from 'data.txt'.
Bash Scripting
declare -A word_counts while read -r [1]; do ((word_counts[[2]][3]1)) done < data.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which subtracts instead of adds.
Using different variable names causing errors.
✗ Incorrect
We read each word into 'word', then increment its count with '+=' operator in the associative array.