LX0-104 · Question #243
Which of the following bash option will prevent an administrator from overwriting a file with a ">"?
The correct answer is C. set -o noclobber. This question identifies the bash option that prevents accidental file overwriting using output redirection.
Question
Options
- Aset -o safe
- Bset -o noglob
- Cset -o noclobber
- Dset -o append
- Eset -o nooverwrite
How the community answered
(49 responses)- B2% (1)
- C94% (46)
- E4% (2)
Why each option
This question identifies the bash option that prevents accidental file overwriting using output redirection.
set -o safe is not a standard bash option for preventing file overwrites.
set -o noglob prevents pathname expansion (globbing), meaning characters like *, ?, and [] are treated as literal characters, not for file matching.
The set -o noclobber (or set -C) bash option prevents the shell from overwriting an existing file using output redirection operators like > or >&. If a file already exists, the redirection attempt will result in an error, protecting the file's contents.
set -o append is not a standard bash option, though >> is the append redirection operator.
set -o nooverwrite is not a standard bash option for preventing file overwrites.
Concept tested: Bash shell options for file protection
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin
Topics
Community Discussion
No community discussion yet for this question.