Quête 104Pipeline-Logician
+260 XP
Exit Codes & Logical Chaining ($?, &&, ||)
Lancer le terminal interactif pour cette quête→Aucune installation requise • S'exécute dans le navigateur
Concept et aperçu
Every command executed in Linux returns an exit status code between 0 and 255 upon completion:
- 0: Success (no errors occurred).
- 1-255: Failure or error code.
- The special shell parameter $? stores the exit code of the immediately preceding command: echo $?.
Shell logic operators chain commands based on exit codes:
- cmd1 && cmd2: Logical AND. Runs cmd2 only if cmd1 succeeds (exit code 0).
- cmd1 || cmd2: Logical OR. Runs cmd2 only if cmd1 fails (non-zero exit code).
Combining them creates clean resilient commands: mkdir backup && cp app.db backup/ || echo "Backup failed".
Instructions de la mission
Check the exit code of a successful command by running
whoami followed by echo $?. Next, use conditional chaining to ensure the directory exists before copying: run mkdir backup && cp app.db backup/ || echo 'Backup failed'.Référence de syntaxe des commandes
| Command / Syntax | Description |
|---|---|
echo $? | Print exit code of the last command |
mkdir backup && cp app.db backup/ || echo 'Backup failed' | Conditionally create directory, copy file, or report failure |
Objectifs de vérification
- ○Inspect last exit code with "echo $?"
- ○Chain backup with "mkdir backup && cp app.db backup/ || echo 'Backup failed'"
- ○Verify app.db copied into backup/