When running the command
sed -e "s/a/b/" /tmp/file >/tmp/file
While /tmp/file contains data, why is /tmp/file empty afterwards?
Suggested Answer: C
Get Premium LFCS Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
15 comments · newest first
CA
Cathern
2 months ago
I feel like C explains the behavior perfectly.
CH
Charlette
2 months ago
D is incorrect. Redirection works with >.
BR
Bronwyn
2 months ago
B could be true if there were no matches, but the file is still empty.
RO
Rory
2 months ago
A is also a possibility, but I lean towards C.
EA
Earnestine
3 months ago
Agreed, C makes the most sense.
EV
Evangelina
3 months ago
I think it's C. The file gets overwritten before sed runs.
RO
Rosio
3 months ago
B doesn't make sense, sed would just output the original content if no match.
BE
Bernadine
3 months ago
No way, D is wrong. Redirection works with >.
LE
Lenna
3 months ago
Wait, I thought it was A at first. That’s surprising!
DO
Donette
3 months ago
Totally agree, C is the right answer.
ID
Idella
4 months ago
It's C! The file gets cleared before sed runs.
NA
Na
4 months ago
I definitely remember that using > overwrites the file, but I don't think option D is correct since > is a valid redirection operator.
AR
Art
4 months ago
I feel like option A could be a possibility, but I can't recall if the order really matters in this case.
TA
Tamala
4 months ago
I think I saw a similar question about sed and file redirection in practice. It might be option C, but I'm not completely confident.
OZ
Ozell
4 months ago
I remember something about how redirection works in the shell, but I'm not entirely sure if it overwrites the file before the command runs.