Bird
0
0

Which of the following is the correct syntax to append text to a file in bash?

easy📝 Syntax Q3 of 15
Bash Scripting - File Operations in Scripts
Which of the following is the correct syntax to append text to a file in bash?
Aecho "Hello" < file.txt
Becho "Hello" > file.txt
Cecho "Hello" | file.txt
Decho "Hello" >> file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand redirection operators in bash

    '>' overwrites a file, '>>' appends to a file, '<' reads from a file, '|' pipes output.
  2. Step 2: Identify the append operator

    To add text without erasing existing content, use '>>'.
  3. Final Answer:

    echo "Hello" >> file.txt -> Option D
  4. Quick Check:

    Append text syntax = echo "text" >> file [OK]
Quick Trick: Use >> to add text without erasing file content [OK]
Common Mistakes:
MISTAKES
  • Using > which overwrites the file
  • Using < which is for input redirection
  • Using | incorrectly as a file redirect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes