A startup file exported http_proxy, and for the rest of this session the variable must be gone completely: neither set nor env should list it any more, and a program started from this shell must not find it even as an empty value. Which command does that?
LPIC-1 Exam 102-500, objective 105. Shells and shell scripting 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 unset http_proxy
Correct. unset removes the variable from the shell altogether, so it disappears from the shell's own variable list and from the environment handed to every child process.
Not correct http_proxy=""
Wrong. The variable still exists and is still exported, now holding an empty string. env prints it as http_proxy= with nothing after the equals sign, and a program that only asks whether the name is set still finds it.
Not correct export -n http_proxy
Wrong for this requirement. The -n option removes only the export attribute. Children stop receiving it, but it remains a shell variable of the current shell and set still lists it.
Not correct readonly http_proxy
Wrong, and it makes the situation permanent. readonly freezes the current value, and a readonly variable cannot be unset afterwards: bash answers a later unset with cannot unset: readonly variable.
Why
Three states are worth telling apart, because programs test them differently. Not set at all is what unset NAME produces. Set but empty is what NAME= produces, and it is still exported, which is why an empty proxy variable can still change a program's behaviour. Set but not exported is what export -n leaves behind: visible to set, invisible to children. unset also removes functions, with unset -f NAME, and plain unset without -f looks for a variable of that name before it looks for a function. The only escape from a readonly variable is a new shell.
Where this comes from
- Cited
- manual page bash(1)
Practise this
Reading one question is not practice. The trainer will draw a short set from objective 105 and space the ones you get wrong.
More questions on this objective
- A user logs in at a text console, and bash starts as an interactive login shell. Which file in that user's home directory is read by bash itself as part of login startup? machine-checked
- You are already logged in to a graphical desktop and open a new terminal window, so bash starts as an interactive shell that is not a login shell. Which per-user file does bash read in that case? machine-checked
- An executable script contains only the line `export EDITOR=vim`. After running it as `./setenv.sh`, `echo $EDITOR` in the calling shell prints nothing. What explains this? machine-checked
- In bash, what is the effect of `export MYVAR`? machine-checked
- At a bash prompt you run `alias ll='ls -l'` and it works for the rest of that session, but a terminal window opened afterwards does not recognise `ll`. Which statement explains this and gives the standard remedy? machine-checked
- A command finishes and the shell reports an exit status of 0. What does that mean, and which parameter reports it? machine-checked