102-500 · Question #34
Which bash option will prevent you from overwriting a file with a ">"?
The correct answer is C. set -o noclobber. set -o noclobber is correct because "noclobber" is the actual bash shell option that causes > to fail with an error if the target file already exists, protecting it from being overwritten. Once set, you can still force an overwrite with >| if needed. Why the distractors are…
Question
Options
- Aset -o safe
- Bset -o noglob
- Cset -o noclobber
- Dset -o append
- Eset -o nooverwrite
How the community answered
(13 responses)- B8% (1)
- C85% (11)
- E8% (1)
Explanation
set -o noclobber is correct because "noclobber" is the actual bash shell option that causes > to fail with an error if the target file already exists, protecting it from being overwritten. Once set, you can still force an overwrite with >| if needed.
Why the distractors are wrong:
- A (
safe) and D (append) and E (nooverwrite) - none of these are valid bashset -ooptions; they simply don't exist in bash. - B (
noglob) - this is a real bash option, but it disables wildcard/glob expansion (e.g.,*.txt), not file overwrite protection.
Memory tip: Think of "clobber" as slang for destroying something - noclobber means "don't destroy my file." If you can remember that > clobbers (destroys) existing file content, the option name writes itself.
Topics
Community Discussion
No community discussion yet for this question.