nerdexam
LPI

101-500 · Question #42

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

The correct answer is C. When the shell establishes the redirection it overwrites the target file before the redirected. You've hit your Sonnet limit · resets Jun 8, 9am (UTC)

Shells and Shell Scripting

Question

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

Options

  • AThe file order is incorrect. The destination file must be mentioned before the command to ensure
  • BThe command sed did not match anything in that file therefore the output is empty.
  • CWhen the shell establishes the redirection it overwrites the target file before the redirected
  • DRedirection for shell commands do not work using the > character. It only works using the |

How the community answered

(42 responses)
  • A
    2% (1)
  • B
    2% (1)
  • C
    86% (36)
  • D
    10% (4)

Explanation

You've hit your Sonnet limit · resets Jun 8, 9am (UTC)

Topics

#Shell I/O Redirection#File Truncation#sed#Input/Output

Community Discussion

No community discussion yet for this question.

Full 101-500 Practice