LX0-104 · Question #535
Which of the following bash options will prevent an administrator from overwriting a file with a ">"?
The correct answer is C. set -o noclobber. The set -o noclobber option in bash prevents existing files from being accidentally overwritten by redirection operators like > and >>.
Question
Options
- Aset -o safe
- Bset -o noglob
- Cset -o noclobber
- Dset -o append
- Eset -o nooverwrite
How the community answered
(22 responses)- A5% (1)
- C91% (20)
- D5% (1)
Why each option
The `set -o noclobber` option in bash prevents existing files from being accidentally overwritten by redirection operators like `>` and `>>`.
`set -o safe` is not a standard bash option.
`set -o noglob` disables pathname expansion (globbing), meaning characters like `*`, `?`, and `[` are treated as literal characters, not for matching filenames.
When `set -o noclobber` (or `set -C`) is enabled, bash prevents redirection operators like `>` from overwriting an existing file, producing an error instead. This is a safety feature to protect important files from accidental deletion or corruption.
`set -o append` is not a standard bash option for this purpose; `>>` is the append operator itself.
`set -o nooverwrite` is not a standard bash option; `noclobber` is the correct option.
Concept tested: Bash shell options - noclobber
Source: https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
Topics
Community Discussion
No community discussion yet for this question.