Run sort names.txt with every locale category set to C only for that command.
Do not change the current shell environment.
Which command is appropriate?
NAME=value COMMAND passes an environment override only to that command without permanently changing the parent shell.
Detailed explanation
export LC_ALL=C; sort names.txtIncorrect. export changes the current shell and subsequent commands.
Incorrect. export changes the current shell and subsequent commands.
sort LC_ALL=C names.txtIncorrect. It treats LC_ALL=C as an input filename.
Incorrect. It treats LC_ALL=C as an input filename.
LANG=C; sort names.txtIncorrect. LANG may still be overridden by existing LC_* values.
Incorrect. LANG may still be overridden by existing LC_* values.
LC_ALL=C sort names.txtCorrect. The prefix applies LC_ALL=C only to sort.
Correct. The prefix applies LC_ALL=C only to sort.
Try it yourself
An example you can run in a temporary verification environment.
before=${LC_ALL-unset}; LC_ALL=C locale LC_ALL; printf '%s
' "${LC_ALL-unset}"Expected result
Cの後に親シェル側の元の値Key points
- Command-scoped assignment
- Do not export
- LC_ALL covers every category
Notes
- Environment: POSIX shell / 親環境を変更しない
- 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.