Make command output parsed by a shell script stable across users with different language settings.
Which setting is a representative choice?
LANG=C selects the portable C locale for categories not overridden elsewhere; LC_ALL still takes precedence.
Detailed explanation
LANG=autoIncorrect. auto is not a portable standard locale name.
Incorrect. auto is not a portable standard locale name.
LC_TIME=localIncorrect. local is not a complete stable locale choice for all categories.
Incorrect. local is not a complete stable locale choice for all categories.
TZ=LANGIncorrect. TZ controls timezone, not locale messages or collation.
Incorrect. TZ controls timezone, not locale messages or collation.
LANG=CCorrect. LANG=C provides predictable default formatting and collation.
Correct. LANG=C provides predictable default formatting and collation.
Try it yourself
An example you can run in a temporary verification environment.
LANG=C LC_ALL= date -d 'invalid-date' 2>&1 | head -n 1Expected result
英語のエラーメッセージ(date実装により文面は異なる)Key points
- C is a standard locale
- Stabilize parsed output
- LC_ALL overrides
Notes
- Environment: GNU date / C locale
- 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.