A sort must run with LC_ALL set to C so that it collates byte by byte, but the rest of your interactive session should keep its normal locale. Which command achieves that?

LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium

Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.

Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

The options

Correct env LC_ALL=C sort data.txt

Correct. env runs the named program with the given assignments added to the environment it passes on. Only that one process sees LC_ALL=C; the shell's own environment is unchanged.

Not correct export LC_ALL=C; sort data.txt

Wrong for the requirement. This does sort correctly, but LC_ALL stays exported for the remainder of the session and for every later command, which is exactly what was to be avoided.

Not correct LC_ALL=C; sort data.txt

Wrong. The assignment and the command are separate statements here, so LC_ALL becomes an ordinary shell variable that is never exported. sort inherits nothing and collates in the current locale.

Not correct set LC_ALL=C; sort data.txt

Wrong. In bash, set manipulates shell options and positional parameters; this line sets $1 to the literal text LC_ALL=C. The C-shell assignment syntax does not apply.

Why

There are two ways to give a single command a modified environment: put the assignment in front of the command name in the same simple command, or invoke it through env. Both leave the shell's own variables alone. A bare assignment on its own line creates a shell variable, and only export promotes a shell variable into the environment that child processes receive.

Where this comes from

Cited
manual page env(1)

Practise this

Reading one question is not practice. The trainer will draw a short set from objective 103 and space the ones you get wrong.

Practise LPIC-1 Exam 101-500

More questions on this objective

All questions on GNU and Unix commands

Practise LPIC-1 Exam 101-500