Bird
0
0

You want to write a script that logs the current date and a message to logfile.txt. Which script correctly appends the date and message on separate lines?

hard🚀 Application Q9 of 15
Bash Scripting - File Operations in Scripts
You want to write a script that logs the current date and a message to logfile.txt. Which script correctly appends the date and message on separate lines?
Adate > logfile.txt echo "Backup completed" >> logfile.txt
Bdate >> logfile.txt echo "Backup completed" >> logfile.txt
Cecho "$(date)" > logfile.txt echo "Backup completed" >> logfile.txt
Decho date >> logfile.txt echo "Backup completed" >> logfile.txt
Step-by-Step Solution
Solution:
  1. Step 1: Append current date command output

    Using date >> logfile.txt appends current date with newline.
  2. Step 2: Append message on next line

    echo with >> appends message on new line.
  3. Final Answer:

    date >> logfile.txt\necho "Backup completed" >> logfile.txt -> Option B
  4. Quick Check:

    Use command >> file to append output [OK]
Quick Trick: Use command >> file to append output [OK]
Common Mistakes:
MISTAKES
  • Using > overwrites file
  • Echoing literal 'date' instead of command output
  • Combining date in echo without command substitution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes