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

Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.

It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.

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 set from objective 105 and space the ones you get wrong.

Practise LPIC-1 Exam 102-500