exam questions

Exam 101-400 All Questions

View all questions & answers for the 101-400 exam

Exam 101-400 topic 3 question 49 discussion

Actual exam question from LPI's 101-400
Question #: 49
Topic #: 3
[All 101-400 Questions]

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

  • A. The file order is incorrect. The destination file must be mentioned before the command to ensure redirection.
  • B. The command sed did not match anything in that file therefore the output is empty.
  • C. When the shell establishes the redirection it overwrites the target file before the redirected command starts and opens it for reading.
  • D. Redirection for shell commands do not work using the > character. It only works using the | character instead.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
DuboisNicolasDuclair
1 year, 4 months ago
Selected Answer: C
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.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago