Practice area
LPIC-1 102: Shells and Shell Scripting
Control shell environment behavior and write small scripts that are predictable, readable, and safe to run repeatedly.
Linux One Liners is an independent study and practice resource. It is not affiliated with, endorsed by, or approved by LPI, The Linux Foundation, CompTIA, or any certification provider. This site does not provide exam dumps or real exam questions.
Source status
Source status: LPI LPIC-1 overview verified July 3, 2026. Current version 5.0; exams 101-500 and 102-500.
This page paraphrases study areas into command practice. It does not copy official objective text wholesale and is not an exam dump.
Plain-English goal
Practice area: shell environment, startup files, aliases, functions, scripts, tests, loops, and exit codes. Exam/domain: 102-500.
read the situation
Command, output, and next step
Command anatomy
printf 'SHELL=%s\nPATH=%s\n' "$SHELL" "$PATH"; env | sort | head -40
printf- the command family
flags- change output shape or scope
target- the file, service, user, mount, or host being inspected
output- evidence you must explain before changing state
Annotated output
Usage: command [OPTION]... TARGET
Try 'command --help' for common flags.
Try 'man command' for full reference.
What to notice
- Usage
- the command shape and expected target
- --help
- quick option reference
- man
- full local manual page when installed
Safe vs unsafe move
Common wrong move
Treating a practice command as a permission to make a broad production change.
Next safe command
command --help
Troubleshooting ladder
- Name the symptom.
- Inspect read-only state.
- Find the owner, service, file, device, mount, or route.
- Read the decisive output field.
- Choose the next narrow command.
- Avoid broad or destructive changes.
- Make the smallest justified change if required.
- Verify and record what changed.
How to get help
- Know the commandUse
command --help, thenman commandfor the full reference. - Know the conceptUse
apropos keywordorman -k keywordto discover command names. - Maybe a shell builtinUse
type command,command -V command, thenhelp command. - Service behaviorUse
systemctl status serviceandjournalctl -u servicebefore restarting. - Package ownershipUse
dpkg -S,rpm -qf, or the distro package tool for the installed file.
Study plan
- Separate login shell, interactive shell, non-interactive script, and cron execution so environment surprises are easier to debug.
- Practice PATH, aliases, functions, variables, quoting, and command substitution with visible output before relying on them.
- Write small scripts with a shebang, input checks, exit-code checks, and clear output for success/failure.
- Connect scripts to scheduled jobs carefully: full paths, logging, predictable locale, and no hidden interactive assumptions.
Command labs
Run these in a lab shell or disposable machine first. The point is to explain the output, not just memorize the command.
Inspect shell environment
printf 'SHELL=%s\nPATH=%s\n' "$SHELL" "$PATH"; env | sort | head -40
Shell path and environment variables should be visible and explainable.
Annotated output
Usage: command [OPTION]... TARGET
Try 'command --help' for common flags.
Try 'man command' for full reference.
What to notice: Usage, --help, man.
Next safe command: command --help
Check cron path assumptions
crontab -l 2>/dev/null; grep -R '^PATH=' /etc/cron* 2>/dev/null | head
User and system cron environment clues should show whether scripts rely on missing paths.
Annotated output
Usage: command [OPTION]... TARGET
Try 'command --help' for common flags.
Try 'man command' for full reference.
What to notice: Usage, --help, man.
Next safe command: command --help
Test script exit behavior
sh -n ./script.sh 2>/dev/null; printf 'syntax_check_exit=%s\n' "$?"
Shell syntax check should return 0 for parseable scripts and nonzero for syntax errors.
Annotated output
Usage: command [OPTION]... TARGET
Try 'command --help' for common flags.
Try 'man command' for full reference.
What to notice: Usage, --help, man.
Next safe command: command --help
command families
Commands to practice
bashshenvexportaliastest[forwhilecasereadsetcrontab
Related drills
Flashcards
Why do cron jobs fail when manual commands work?
Cron often has a smaller environment and PATH than an interactive shell.
What does sh -n do?
It checks shell syntax without executing the script body.
Why quote variables in shell scripts?
Quoting prevents word splitting and glob expansion surprises.
What does an exit code of 0 conventionally mean?
Success; nonzero usually means failure or a special condition.
Quick quiz
Check the reasoning locally in your browser. Answers are not sent anywhere.