Which THREE of the following are common practices to improve the reliability of shell scripts?
Quoting variable expansions such as "$var" or "${var}" prevents the shell from performing word splitting (splitting the value on characters in IFS, typically whitespace) and pathname expansion (globbing) on the resulting tokens. Without quotes, a variable containing spaces or glob characters like '*' can be broken into multiple arguments or expanded into filenames in unexpected ways. Consistent quoting ensures that the value of the variable is passed as a single argument, which is essential for correctly handling filenames, paths, or data with special characters.
Why this answer
Option A is correct because quoting variable expansions such as "$var" prevents unintended word splitting and glob expansion, which are common sources of bugs and failures in shell scripts. Option C is correct because 'set -u' causes the shell to treat references to unset variables as an error and exit, catching typos and missing environment variables early. Option D is correct because 'set -e' makes the script exit immediately when a command returns a non-zero status, preventing execution from continuing after a failure.
Option B is not a reliability practice: 'echo "Error"' without redirection writes to stdout rather than stderr, so error messages may be missed or mixed with normal output. Option E is not recommended: using 'cat' to feed a while loop spawns an extra process and is less efficient than redirecting the file directly into the loop, and it does not by itself improve reliability.
Exam trap
The RHCSA exam often tests the misconception that 'echo' is sufficient for error output without considering redirection to stderr, and that 'cat' in while loops is a safe pattern, when in fact it introduces performance and reliability issues.