0
0
Bash Scriptingscripting~10 mins

Report generation script in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A-d
B+%H:%M:%S
C+%Y-%m-%d
D-u
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.
2fill in blank
medium

Complete 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'
A-w data.txt
Bdata.txt
C-c data.txt
D-m data.txt
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'.
3fill in blank
hard

Fix 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'
A>>
B|
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' which overwrites the file.
Using '<' which is input redirection.
Using '|' which pipes output to another command.
4fill in blank
hard

Fill 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'
A""
Bline
Cword
D' '
Attempts:
3 left
💡 Hint
Common Mistakes
Setting IFS to a space which splits words, not lines.
Using 'word' which is misleading for line reading.
5fill in blank
hard

Fill 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'
Aword
C+=
D-=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which subtracts instead of adds.
Using different variable names causing errors.