When running the command -
sed -e "s/a/b/" /tmp/file >/tmp/file
While /tmp/file contains data, why is /tmp/file empty afterwards?
When running the command -
sed -e "s/a/b/" /tmp/file >/tmp/file
While /tmp/file contains data, why is /tmp/file empty afterwards?
When the shell establishes the redirection, it overwrites the target file before the redirected command starts and opens it for reading. In this case, the shell processes the `>/tmp/file` redirection before the `sed` command can read the original `/tmp/file` content. As a result, the file is emptied before `sed` can process it, leaving `/tmp/file` empty.
The reason `/tmp/file` is empty after running the command: C. When the shell establishes the redirection, it overwrites the target file before the redirected command starts and opens it for reading. In this scenario, the shell processes the redirection before the `sed` command is executed. As a result, the output file, `/tmp/file`, is emptied before `sed` even begins processing the data from the input file. This is why the file ends up empty.