The first echo writes "Hello" to output.txt, overwriting any existing content.
Step 2: Analyze second echo command
The second echo appends "World" to output.txt, adding it on a new line.
Final Answer:
Hello
World -> Option A
Quick Check:
First overwrite, then append with newline [OK]
Hint: > overwrites file, >> appends with newline [OK]
Common Mistakes:
Thinking >> overwrites instead of appends
Ignoring newline added by echo
Assuming output is just 'Hello' or 'World'
4. Identify the error in this script that tries to read from a file and print its content:
cat < input.txt
medium
A. The command should be 'cat >> input.txt' to append content.
B. The file name should be after the command without <, like 'cat > input.txt'.
C. The input redirection < is unnecessary; use 'cat input.txt' instead.
D. The script needs quotes around the file name.
Solution
Step 1: Understand cat command usage
cat reads and prints file content when given the filename as an argument.
Step 2: Check input redirection usage
Using < input.txt is valid but redundant here; 'cat input.txt' is simpler and standard.
Final Answer:
The input redirection < is unnecessary; use 'cat input.txt' instead. -> Option C
Quick Check:
cat filename is simpler than cat < filename [OK]
Hint: Use 'cat filename' to read files, not input redirection [OK]
Common Mistakes:
Confusing input redirection with output redirection
Using > or >> instead of < for input
Adding unnecessary quotes around filename
5. You want to create a script that reads a list of usernames from users.txt and writes a greeting for each user into greetings.txt. Which script snippet correctly does this?
hard
A. while read user; do echo "Hello, $user!" >> greetings.txt; done < users.txt
B. for user in users.txt; do echo "Hello, $user!" > greetings.txt; done
C. cat users.txt | echo "Hello, $user!" > greetings.txt
D. echo "Hello, $(cat users.txt)!" > greetings.txt
Solution
Step 1: Understand reading lines from a file
The 'while read user; do ... done < users.txt' reads each line (username) from users.txt correctly.
Step 2: Check writing greetings
Inside the loop, echo appends a greeting line to greetings.txt for each user.
Final Answer:
while read user; do echo "Hello, $user!" >> greetings.txt; done < users.txt -> Option A
Quick Check:
Loop reads lines and appends greetings [OK]
Hint: Use while read loop with input redirection and append >> [OK]
Common Mistakes:
Using for loop incorrectly on filename instead of lines
Overwriting greetings.txt inside loop instead of appending
Misusing cat with echo without looping
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.