QuestionQ72

VerifiedEssential Commands

When executing the command:

sed -e "s/a/b/" /tmp/file >/tmp/file  

while /tmp/file contains data, why is /tmp/file empty afterward?

Explanation

The shell opens and truncates the file named by > before starting sed. Since sed then opens that same file as its input, it reads an already-empty file and writes no transformed content.

Community Discussion

No comments yet. Be the first to start the discussion!