Interview › Scripting (Bash, Groovy)
Why is set -euo pipefail considered a safe default for scripts? [Basic]
Answer
set -euo pipefail is considered a safer default because it stops many scripts from continuing with failed commands, unset variables, or hidden pipeline failures. It makes failures more visible and reduces silent data corruption.
Technical explanation
It is useful for deployment, backup, and maintenance scripts where continuing after an error can be dangerous.
It should be paired with intentional exception handling for commands whose failure is expected.
It makes scripts stricter, so optional variables should use defaults like ${var:-default} and required variables should use ${var:?message}.
Hands-on example
#!/usr/bin/env bash
set -euo pipefail
backup_dir=${BACKUP_DIR:-/var/backups/app}
mkdir -p "$backup_dir"
pg_dump app > "$backup_dir/app.sql"
gzip -f "$backup_dir/app.sql"Preparing for an interview?
Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.
More Scripting (Bash, Groovy) interview questions
- What do set -e, set -u, set -o pipefail, and set -x do? [Basic]
- What does an exit code of 0 versus non-zero mean? [Basic]
- What is the difference between [ ], [[ ]], and (( )) in Bash? [Basic]
- What is $? used for, and how do you check the exit status of a command? [Basic]
- What are the common file test operators (-f, -d, -e, -r, -w, -x)? [Basic]
- What is command substitution, and what is the difference between $(...) and backticks? [Basic]
- How do you write a for loop over a list and a C-style for loop? [Basic]
- What is the difference between single quotes and double quotes in Bash? [Basic]