Defensive Shell Programming
Final Quiz
Connecting to LMS...
Progress: in progress
Assessment
1. Why should shell scripts be treated as real operational software?
A. Because all shell scripts are large applications.
B. Because they may run with meaningful permissions, touch important systems, and become production dependencies.
C. Because shell scripts cannot be reviewed.
D. Because scripts do not affect production systems.
2. What does quoting a shell variable usually help preserve?
A. Argument boundaries.
B. Network encryption.
C. Administrator privileges.
D. A hidden copy of the command.
3. Why can unquoted variables be risky?
A. They disable exit codes.
B. They prevent commands from running.
C. They may be affected by word splitting or glob expansion.
D. They always delete files.
4. Which input sources should defensive scripts treat carefully?
A. Only values longer than one line.
B. Only interactive keyboard input.
C. Only values from public websites.
D. Arguments, environment variables, configuration files, filenames, standard input, and command output.
5. What is a good way to validate a script mode such as backup, verify, or status?
A. Accept any mode and let later commands decide.
B. Remove spaces and assume it is safe.
C. Compare it against an allowlist of supported values.
D. Treat unknown modes as production.
6. Why is it important to check command results?
A. Checking results hides operational problems.
B. Continuing after a failed command can cause partial changes, misleading results, or unsafe behavior.
C. Quoted commands never fail.
D. Exit status only matters in compiled languages.
7. What is a limitation of strict mode options such as set -e?
A. They can help catch failures, but they do not replace deliberate error handling and review.
B. They validate all input automatically.
C. They make every script safe to run as root.
D. They redact secrets from logs.
8. Why should scripts use safe temporary-file patterns?
A. Safe temporary files replace authorization.
B. Temporary files never need cleanup.
C. Temporary files are always private.
D. Predictable or careless temporary files can cause collisions, exposure, or unsafe file operations.
9. What is one risk of putting secrets in command-line arguments?
A. They automatically expire after one second.
B. They cannot be read by programs.
C. They are encrypted by the shell.
D. They may appear in process listings, logs, history, or diagnostic output.
10. What is a good logging practice for defensive shell scripts?
A. Print tokens when a command fails.
B. Log every environment variable.
C. Log useful actions and failures while avoiding secrets or sensitive data.
D. Write all errors to a file with public permissions.
11. Why is a dry-run mode useful?
A. It lets operators preview intended actions before making changes.
B. It removes the need for review.
C. It prevents every script failure.
D. It guarantees future production success.
12. What is the main goal of defensive shell programming?
A. To hide failures from maintainers.
B. To make automation predictable, reviewable, and safer to operate.
C. To make every script complex.
D. To prevent all automation.
Submit Quiz
Previous