{
"$schema": "../schema/questions.schema.json",
"format": "lpic-sim-questions",
"meta": {
"file": "questions_105.json",
"brief": "Fragen zu Topic 105 Shells und Shell-Skripte (LPIC-1 102-500, Objectives 5.0)",
"author": "Björn Runden
",
"owner": "Björn Runden
",
"assist": "KI-unterstützt (Claude Opus 5.5), geprüft von Björn Runden
",
"version": "0.1.0 (29.10.2026)"
},
"exam": "lpic1-102",
"questions": [
{
"id": "105.1-001",
"objective": "105.1",
"type": "single",
"difficulty": 2,
"question": "Welche Datei liest eine interaktive **Login**-Bash als erste ein?",
"options": [
{ "id": "a", "text": "`/etc/profile`", "correct": true, "explanation": "Login-Shells lesen zuerst die systemweite `/etc/profile`, danach die erste vorhandene aus `~/.bash_profile`, `~/.bash_login`, `~/.profile`." },
{ "id": "b", "text": "`~/.bashrc`", "correct": false, "explanation": "`~/.bashrc` lesen interaktive Nicht-Login-Shells; Login-Shells nur, wenn `~/.bash_profile` sie einbindet." },
{ "id": "c", "text": "`~/.bash_profile`", "correct": false, "explanation": "Wird gelesen, aber erst nach `/etc/profile`." },
{ "id": "d", "text": "`/etc/bash.bashrc`", "correct": false, "explanation": "Systemweite Datei für interaktive Nicht-Login-Shells (Debian); wird oft über `/etc/profile` eingebunden." },
{ "id": "e", "text": "`~/.bash_logout`", "correct": false, "explanation": "Wird beim Beenden einer Login-Shell ausgeführt." }
],
"explanation": "Login-Shell: `/etc/profile` → `~/.bash_profile` | `~/.bash_login` | `~/.profile`. Nicht-Login-Shell: `/etc/bash.bashrc` (distributionsabhängig) → `~/.bashrc`.",
"references": ["man 1 bash (Abschnitt INVOCATION)"]
},
{
"id": "105.1-002",
"objective": "105.1",
"type": "multi",
"difficulty": 1,
"question": "Welche Schreibweisen definieren in der Bash korrekt eine Funktion `gruss`?",
"options": [
{ "id": "a", "text": "`gruss() { echo Hallo; }`", "correct": true, "explanation": "POSIX-Schreibweise; vor der schließenden Klammer ist `;` oder ein Zeilenumbruch nötig." },
{ "id": "b", "text": "`function gruss { echo Hallo; }`", "correct": true, "explanation": "Bash-spezifische Schreibweise mit dem Schlüsselwort `function`." },
{ "id": "c", "text": "`def gruss(): echo Hallo`", "correct": false, "explanation": "Das ist Python-ähnliche Syntax." },
{ "id": "d", "text": "`gruss = { echo Hallo }`", "correct": false, "explanation": "Leerzeichen um `=` und diese Klammerung sind keine gültige Funktionssyntax." },
{ "id": "e", "text": "`alias gruss() echo Hallo`", "correct": false, "explanation": "Aliase werden mit `alias name='befehl'` gesetzt und haben keine Klammern." }
],
"explanation": "Funktionen sehen Argumente als `$1`, `$2`, …; `declare -f` listet definierte Funktionen. Dauerhaft z. B. in `~/.bashrc`.",
"references": ["man 1 bash (Abschnitt FUNCTIONS)"]
},
{
"id": "105.1-003",
"objective": "105.1",
"type": "fill",
"difficulty": 2,
"question": "Welches Bash-Builtin führt die Befehle einer Datei in der **aktuellen** Shell aus, sodass dort gesetzte Variablen danach erhalten bleiben? (Name des Builtins)",
"answers": ["source", "."],
"explanation": "`source ~/.bashrc` bzw. `. ~/.bashrc`. Ein Aufruf als `./datei` oder `bash datei` läuft dagegen in einer Subshell; deren Variablen gehen verloren.",
"references": ["help source"]
},
{
"id": "105.1-004",
"objective": "105.1",
"type": "single",
"difficulty": 1,
"question": "Der Alias `ll='ls -l'` soll für einen Benutzer dauerhaft in jeder interaktiven Bash verfügbar sein. Wo trägt man ihn ein?",
"options": [
{ "id": "a", "text": "`~/.bashrc`", "correct": true, "explanation": "`~/.bashrc` wird von jeder interaktiven Nicht-Login-Bash gelesen und meist auch aus `~/.bash_profile` eingebunden." },
{ "id": "b", "text": "`/etc/aliases`", "correct": false, "explanation": "`/etc/aliases` enthält E-Mail-Aliase für den MTA, keine Shell-Aliase." },
{ "id": "c", "text": "`~/.bash_logout`", "correct": false, "explanation": "Wird nur beim Abmelden ausgeführt." },
{ "id": "d", "text": "`/etc/shells`", "correct": false, "explanation": "`/etc/shells` listet die zulässigen Login-Shells." },
{ "id": "e", "text": "`~/.bash_history`", "correct": false, "explanation": "Enthält nur die gespeicherte Befehls-History." }
],
"explanation": "Ein Alias in der Shell gilt nur bis zum Ende der Sitzung; dauerhaft wird er durch einen Eintrag in einer Startdatei.",
"references": ["help alias"]
},
{
"id": "105.1-005",
"objective": "105.1",
"type": "single",
"difficulty": 1,
"question": "Das Verzeichnis `/opt/tools/bin` soll **zusätzlich** zum bisherigen Suchpfad verwendet werden. Welcher Befehl ist korrekt?",
"options": [
{ "id": "a", "text": "`export PATH=$PATH:/opt/tools/bin`", "correct": true, "explanation": "Der alte Inhalt bleibt erhalten, das neue Verzeichnis wird mit `:` angehängt." },
{ "id": "b", "text": "`export PATH=/opt/tools/bin`", "correct": false, "explanation": "Ersetzt den Suchpfad; Standardbefehle wie `ls` werden nicht mehr gefunden." },
{ "id": "c", "text": "`export PATH=$PATH;/opt/tools/bin`", "correct": false, "explanation": "`;` trennt Befehle; die Shell würde `/opt/tools/bin` als Befehl ausführen." },
{ "id": "d", "text": "`export $PATH=$PATH:/opt/tools/bin`", "correct": false, "explanation": "Links vom `=` steht der Variablenname ohne `$`." },
{ "id": "e", "text": "`set PATH /opt/tools/bin`", "correct": false, "explanation": "Das ist csh-Syntax; in der Bash setzt `set` Positionsparameter." }
],
"explanation": "Verzeichnisse im `PATH` werden von links nach rechts durchsucht; `$PATH` voranzustellen oder anzuhängen bestimmt die Priorität.",
"references": ["man 1 bash (Abschnitt Shell Variables)"]
},
{
"id": "105.1-006",
"objective": "105.1",
"type": "single",
"difficulty": 1,
"question": "Welches Verzeichnis enthält die Vorlagen (z. B. `.bashrc`, `.profile`), die beim Anlegen eines Benutzers mit `useradd -m` in dessen Home-Verzeichnis kopiert werden?",
"options": [
{ "id": "a", "text": "`/etc/skel`", "correct": true, "explanation": "Der Inhalt von `/etc/skel` wird in neue Home-Verzeichnisse kopiert." },
{ "id": "b", "text": "`/etc/default/useradd`", "correct": false, "explanation": "Datei mit Standardwerten für `useradd` (u. a. `SKEL=`), kein Vorlagenverzeichnis." },
{ "id": "c", "text": "`/etc/profile.d`", "correct": false, "explanation": "Enthält Skripte, die `/etc/profile` beim Login einbindet." },
{ "id": "d", "text": "`/etc/login.defs`", "correct": false, "explanation": "Datei mit Vorgaben wie UID-Bereichen und Passwort-Alterung." },
{ "id": "e", "text": "`/home/template`", "correct": false, "explanation": "Kein Standardpfad." }
],
"explanation": "Änderungen an `/etc/skel` wirken nur für künftig angelegte Benutzer.",
"references": ["man 8 useradd"]
},
{
"id": "105.2-001",
"objective": "105.2",
"type": "single",
"difficulty": 1,
"question": "Welche Variable enthält in einem Shell-Skript die **Anzahl** der übergebenen Argumente?",
"options": [
{ "id": "a", "text": "`$#`", "correct": true, "explanation": "`$#` ist die Anzahl der Positionsparameter." },
{ "id": "b", "text": "`$0`", "correct": false, "explanation": "`$0` ist der Name des Skripts." },
{ "id": "c", "text": "`$@`", "correct": false, "explanation": "`$@` sind alle Argumente als einzelne Wörter." },
{ "id": "d", "text": "`$?`", "correct": false, "explanation": "`$?` ist der Exit-Status des letzten Befehls." },
{ "id": "e", "text": "`$$`", "correct": false, "explanation": "`$$` ist die PID der Shell." }
],
"explanation": "Weitere: `$1`…`$9` Argumente, `${10}` ab dem zehnten, `$*` alle als ein Wort (in Anführungszeichen), `shift` verschiebt die Argumente.",
"references": ["man 1 bash (Abschnitt Special Parameters)"]
},
{
"id": "105.2-002",
"objective": "105.2",
"type": "single",
"difficulty": 1,
"question": "Mit welcher Bedingung prüft ein Skript, ob `/etc/app.conf` existiert **und eine reguläre Datei** ist?",
"options": [
{ "id": "a", "text": "`[ -f /etc/app.conf ]`", "correct": true, "explanation": "`-f` ist wahr für existierende reguläre Dateien." },
{ "id": "b", "text": "`[ -d /etc/app.conf ]`", "correct": false, "explanation": "`-d` prüft auf ein Verzeichnis." },
{ "id": "c", "text": "`[ -e /etc/app.conf ]`", "correct": false, "explanation": "`-e` prüft nur auf Existenz, gleich welcher Typ (auch Verzeichnis)." },
{ "id": "d", "text": "`[ -x /etc/app.conf ]`", "correct": false, "explanation": "`-x` prüft auf Ausführbarkeit." },
{ "id": "e", "text": "`[ -L /etc/app.conf ]`", "correct": false, "explanation": "`-L` prüft auf einen symbolischen Link." }
],
"explanation": "`[ … ]` ist der Befehl `test`; Leerzeichen innerhalb der Klammern sind Pflicht. Weitere Tests: `-s` nicht leer, `-r`/`-w` lesbar/schreibbar, `-z`/`-n` leerer/nicht leerer String.",
"references": ["man 1 test"]
},
{
"id": "105.2-003",
"objective": "105.2",
"type": "fill",
"difficulty": 1,
"question": "Welche spezielle Variable enthält den Exit-Status (Rückgabewert) des zuletzt ausgeführten Befehls?",
"answers": ["$?"],
"explanation": "0 bedeutet Erfolg, alles andere einen Fehler. Darauf bauen `&&`, `||` und `if` auf.",
"references": ["man 1 bash (Abschnitt Special Parameters)"]
},
{
"id": "105.2-004",
"objective": "105.2",
"type": "single",
"difficulty": 1,
"question": "Welche Schleife ist in der Bash syntaktisch korrekt?",
"options": [
{ "id": "a", "text": "`for i in 1 2 3; do echo $i; done`", "correct": true, "explanation": "Aufbau: `for in ; do … done`." },
{ "id": "b", "text": "`for i in 1 2 3; then echo $i; fi`", "correct": false, "explanation": "`then`/`fi` gehören zu `if`." },
{ "id": "c", "text": "`for (i in 1 2 3) { echo $i }`", "correct": false, "explanation": "C/JavaScript-ähnliche Syntax; die Bash kennt das nicht." },
{ "id": "d", "text": "`foreach i (1 2 3) echo $i end`", "correct": false, "explanation": "`foreach … end` ist csh-Syntax." },
{ "id": "e", "text": "`for i = 1 to 3; do echo $i; done`", "correct": false, "explanation": "BASIC-ähnlich; nicht gültig. Zahlenreihen: `$(seq 1 3)` oder `{1..3}`." }
],
"explanation": "Weitere Schleifen: `while bedingung; do … done`, `until …`. C-Stil in der Bash: `for ((i=1; i<=3; i++)); do … done`.",
"references": ["man 1 bash (Abschnitt Compound Commands)"]
},
{
"id": "105.2-005",
"objective": "105.2",
"type": "multi",
"difficulty": 2,
"question": "Welche Aussagen zum Ausführen von Shell-Skripten treffen zu?",
"options": [
{ "id": "a", "text": "Die erste Zeile `#!/bin/bash` legt den Interpreter fest, wenn das Skript direkt ausgeführt wird.", "correct": true, "explanation": "Der Kernel wertet die Shebang-Zeile aus und startet den angegebenen Interpreter." },
{ "id": "b", "text": "Für den Aufruf `./skript.sh` braucht die Datei das Ausführungsrecht.", "correct": true, "explanation": "Ohne `x`-Recht meldet die Shell „Permission denied“." },
{ "id": "c", "text": "Auch `bash skript.sh` funktioniert nur mit Ausführungsrecht.", "correct": false, "explanation": "Hier ist `bash` das ausgeführte Programm; es braucht nur Leserecht auf das Skript." },
{ "id": "d", "text": "Die Shebang-Zeile darf an beliebiger Stelle im Skript stehen.", "correct": false, "explanation": "Sie wirkt nur als allererste Zeile und muss mit `#!` beginnen." },
{ "id": "e", "text": "Das aktuelle Verzeichnis ist standardmäßig im `PATH`; `skript.sh` ohne `./` genügt.", "correct": false, "explanation": "Aus Sicherheitsgründen steht `.` normalerweise nicht im `PATH`." }
],
"explanation": "SUID/SGID-Bits werden bei Skripten unter Linux ignoriert. Mit `exec` ersetzt ein Skript sich selbst durch ein anderes Programm.",
"references": ["man 2 execve"]
},
{
"id": "105.2-006",
"objective": "105.2",
"type": "single",
"difficulty": 1,
"question": "Welcher Befehl liest in einem Skript eine Zeile von der Tastatur in die Variable `NAME` ein?",
"options": [
{ "id": "a", "text": "`read NAME`", "correct": true, "explanation": "`read` liest eine Zeile von stdin; `-p \"Text\"` zeigt vorher eine Eingabeaufforderung an." },
{ "id": "b", "text": "`input NAME`", "correct": false, "explanation": "Einen Befehl `input` gibt es in der Bash nicht." },
{ "id": "c", "text": "`echo $NAME`", "correct": false, "explanation": "Gibt den Inhalt der Variable aus, liest nichts ein." },
{ "id": "d", "text": "`NAME < /dev/stdin`", "correct": false, "explanation": "Die Shell versucht, einen Befehl namens `NAME` auszuführen; eine Variable wird nicht gesetzt." },
{ "id": "e", "text": "`get NAME`", "correct": false, "explanation": "Einen Befehl `get` gibt es in der Bash nicht." }
],
"explanation": "Mehrere Variablen: `read VORNAME NACHNAME` verteilt die Wörter nach `IFS`. Ohne Variablenname landet die Eingabe in `REPLY`.",
"references": ["help read"]
}
]
}