LPIC-1 Exam 101 (Linux Administrator) — Question 49

When running the command -
sed -e "s/a/b/" /tmp/file >/tmp/file
While /tmp/file contains data, why is /tmp/file empty afterwards?

Answer options

Correct answer: C

Explanation

The correct answer is C because when the shell processes the command, it creates the output file first, which clears its contents before sed has a chance to read it. Options A and D are incorrect as they misinterpret how shell redirection works, while B is wrong because the sed command is designed to make substitutions if matches exist.