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?
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 An alias defined at the prompt exists only inside that one shell; writing the same alias line into ~/.bashrc makes every new interactive shell define it.
Correct. Aliases live in the shell's own memory and are neither exported nor inherited, so each new shell starts with only the aliases its startup files define. ~/.bashrc is read by interactive non-login shells, which is exactly what a new terminal window starts.
Not correct Aliases are part of the environment, so the new terminal would have inherited it had that terminal been started as a login shell.
Wrong. Aliases are not environment variables and are never inherited through the environment, whatever kind of shell the child is. Only exported variables cross the fork/exec boundary.
Not correct Aliases are session-only by design, but the same abbreviation written as a shell function, `ll() { ls -l; }`, persists across sessions.
Wrong. A function defined at the prompt is exactly as temporary as an alias; it too must be placed in a startup file to reappear. Functions are preferable to aliases when the abbreviation needs to handle its arguments, not because they persist.
Not correct The alias was lost because it was never written out; running `history -w` before closing the terminal would have saved it.
Wrong. `history -w` flushes the command history to ~/.bash_history. That records the text you typed, but bash never replays the history file as commands at startup, so the alias is not recreated.
Why
`alias` with no arguments lists the aliases currently defined, `alias NAME='command'` defines one and `unalias NAME` (or `unalias -a` for all of them) removes them. Because aliases are per-shell, persistence means putting the definition in a startup file that the shells you care about read: ~/.bashrc for your own interactive shells, /etc/bash.bashrc or a file in /etc/profile.d for everyone. Note also that bash does not expand aliases in non-interactive shells, so an alias in ~/.bashrc has no effect inside a script.
Where this comes from
- Cited
- LPI exam objective 105.1
- What it says
- Use and define aliases, and know which startup files make them persistent.
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
- A command finishes and the shell reports an exit status of 0. What does that mean, and which parameter reports it? machine-checked
- Which statement correctly distinguishes bash's `[[ ... ]]` from `[ ... ]`? machine-checked