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
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 is the purpose of the shebang line, and what does #!/bin/bash do? [Basic]
- What is the difference between sh and bash? [Basic]
- How do you make a script executable and run it? [Basic]
- What is the difference between running a script with ./script.sh, bash script.sh, and source script.sh? [Basic]
- What does sourcing a script do differently from executing it? [Basic]
- How do you declare a variable in Bash, and why are spaces around = not allowed? [Basic]
- What is the difference between $var and ${var}? [Basic]
- What is the difference between single quotes and double quotes in Bash? [Basic]