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.
More questions on this objective
- A user starts a new terminal window in a running graphical desktop session, which launches bash as an interactive shell that is NOT a login shell. Which file in the user's home directory does bash read in that case? machine-checked
- In bash, which history expansion re-runs the entire previous command line? machine-checked
- Which bash command prints the literal five characters $USER instead of the current user name? machine-checked
- You want /opt/bin searched for executables, after all the directories already in PATH, in the current bash session and in every command started from it. Which command does that? machine-checked
- There is a passwd manual page in section 1 (the command) and another in section 5 (the /etc/passwd file format). Which command opens the section 5 page? machine-checked
- Select the TWO true statements about shell variables and the environment in bash. machine-checked