Shells and shell scripting
Shells and shell scripting covers customising the shell environment and writing simple scripts: startup files, variables and aliases, exit status, conditionals, loops and positional parameters. Objective 105 of LPIC-1 Exam 102-500, worth 15% of the exam.
- Share of the exam
- 15%
- Questions in a real sitting
- roughly 9 of 60
- Questions in this bank
- 45
- Signed for by a person
- 0
- Machine-checked only
- 45
Partly checked. None of the 45 questions here has been read against the cited source by a person. 45 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
What this objective covers
The 45 questions written for this objective cite 2 LPI exam objectives (105.1, 105.2) and 4 manual pages (bash(1), execve(2), test(1), useradd(8)).
They break down as 30 single-answer questions, 7 choose-several questions and 8 type-the-answer questions.
What this objective is really about
Two halves that share a foundation. The first is the shell as an environment you configure; the second is the shell as a language you write in. Both come back repeatedly to one idea: what a child process inherits from its parent, and what it cannot change about it.
The environment, and why sourcing exists
Executing a script forks a new process. Anything that process changes — variables, working directory, umask — dies with it, which is why running a script that exports a variable leaves your own shell unchanged. Sourcing with . or source does not fork: the commands run in the current shell and their effects persist. That is the whole reason ~/.bashrc is sourced rather than executed, and it is the most commonly examined fact in this objective.
Aliases are per-shell and are never inherited, so making one permanent means putting it in a startup file. Note also that bash does not expand aliases in non-interactive shells, so an alias in .bashrc has no effect inside a script.
Scripting
A script starts with a shebang — #! as the very first two bytes, followed by an absolute path to the interpreter. #!/bin/sh selects the POSIX shell, which on Debian-family systems is dash and will reject bash-only syntax such as [[ ]] and arrays.
Exit status 0 means success and non-zero means failure, which is the opposite of the truthiness convention in most languages. $? holds the status of the last foreground command and is overwritten by the very next one. && runs the right-hand side only on success and || only on failure; both are driven purely by the status, never by output.
Positional parameters are $1 upward, $# is their count excluding $0, and $0 is the name the script was invoked as. When forwarding arguments, use "$@" — it produces one word per argument and is the only form that keeps an argument containing spaces intact. "$*" joins everything into a single word.
[ is a command whose last argument must be ], which is why the spaces are mandatory. [[ ]] is bash syntax rather than a command, so word splitting and globbing are not applied to unquoted variables inside it, which makes it markedly safer. Use [ for portable /bin/sh scripts and [[ ]] for bash-only ones. Loops close with done, if closes with fi, and case closes with esac.
Lessons in this objective
The objective cut into the pieces the blueprint declares. Each one has the material written out and the questions that test it.
Drill this objective
The trainer can run a short practice set drawn from this objective alone, which is what the weight column above is for: revise the heavy objectives first.
Practise Shells and shell scripting
Questions on this objective (page 1 of 3)
- 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
- Which statement correctly distinguishes bash's `[[ ... ]]` from `[ ... ]`? machine-checked
- Inside a shell script, which special parameter expands to the number of positional parameters the script was given? machine-checked
- A script contains the line `mkdir /srv/data && cp report.txt /srv/data/`. Under what condition does the cp run? machine-checked
- Which keyword closes a `case` construct in a bash script? machine-checked
- A script is called with two arguments: `./run.sh "annual report" 2026`. How does `"$@"` differ from `"$*"` when the script passes them on to another command? machine-checked
- The file setenv.sh, in the current directory, sets and exports several variables. You are in an interactive bash shell running with default options (not POSIX mode). Which two invocations leave those variables set in that shell after the file has run? (Choose two.) machine-checked
- Which three loop headers cause a bash script to iterate exactly over the numbers 1 to 5? Assume default bash options and an empty current directory. (Choose three.) machine-checked
- Which three commands print the current value of the PATH variable to the terminal? (Choose three.) machine-checked
- Type the first line a script must contain so that the kernel runs it with the Bourne Again shell installed at /bin/bash. machine-checked
- Type the special parameter, including its leading dollar sign, that expands to the exit status of the most recently completed foreground command. machine-checked
- Using symbolic mode and changing no other permission bits, type the command that adds the execute permission for all three permission classes (user, group and other) to the file backup.sh in the current directory. machine-checked
- Type the bash builtin command, with its argument, that reads one line from standard input and stores it in the shell variable named ANSWER. machine-checked
- On a Debian server you must set a prompt and a couple of aliases for every user, and they must apply to the terminal windows users open inside their desktop session, not only to console logins. Which system-wide file is the right place for those settings? machine-checked
- A user's home directory contains both ~/.bash_profile and ~/.profile. Settings added to ~/.profile have no effect when the user logs in at a console. What explains this? machine-checked
Practise Shells and shell scripting
The other objectives in LPIC-1 Exam 102-500
- 106. User interfaces and desktops — 6.67% of the exam
- 107. Administrative tasks — 20% of the exam
- 108. Essential system services — 18.33% of the exam
- 109. Networking fundamentals — 23.33% of the exam
- 110. Security — 16.67% of the exam