Give sort the contents of unsorted.txt through standard input.
Do not pass the filename as sort's ordinary argument.
Which command is appropriate?
< FILE opens FILE for reading and connects it to file descriptor 0, standard input.
Detailed explanation
sort > unsorted.txtIncorrect. > redirects sort's stdout and would overwrite the file.
Incorrect. > redirects sort's stdout and would overwrite the file.
sort >> unsorted.txtIncorrect. >> appends sort's stdout to the file.
Incorrect. >> appends sort's stdout to the file.
sort < unsorted.txtCorrect. sort < unsorted.txt connects the file to standard input.
Correct. sort < unsorted.txt connects the file to standard input.
sort 2< unsorted.txtIncorrect. 2< operates on file descriptor 2, not normal standard input.
Incorrect. 2< operates on file descriptor 2, not normal standard input.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); printf 'b\na\n' >"$tmp"; sort <"$tmp"; rm -f "$tmp"Expected result
a
bKey points
- File descriptor 0 is stdin
- < redirects input
- The source file is not modified
Notes
- Environment: Bash 5.x / GNU sort / 一時ファイル
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.