Apply LC_ALL=C only to one sort invocation of names.txt.
Do not change LC_ALL in the current shell.
Which command is appropriate?
NAME=value COMMAND assigns a temporary environment value for that simple command only.
Detailed explanation
export LC_ALL=C; sort names.txtIncorrect. export leaves LC_ALL=C in the current shell.
Incorrect. export leaves LC_ALL=C in the current shell.
LC_ALL=C; sort names.txtIncorrect. A standalone assignment leaves the shell variable defined afterward.
Incorrect. A standalone assignment leaves the shell variable defined afterward.
sort LC_ALL=C names.txtIncorrect. LC_ALL=C is treated as a sort argument in that position.
Incorrect. LC_ALL=C is treated as a sort argument in that position.
LC_ALL=C sort names.txtCorrect. The assignment immediately before sort applies only to sort's environment.
Correct. The assignment immediately before sort applies only to sort's environment.
Try it yourself
An example you can run in a temporary verification environment.
bash --noprofile --norc -c 'unset LC_ALL; LC_ALL=C sh -c '\''printf "child=%s\n" "$LC_ALL"'\''; printf "parent=%s\n" "${LC_ALL-unset}"'Expected result
child=Cの後にparent=unsetKey points
- Assignment before command
- One-command scope
- No parent-shell change
Notes
- Environment: GNU Bash 5.2 / 一時子プロセス
- 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.