nerdexam
LPI

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…

Shells and Shell Scripting

Question

Which bash option will prevent you from overwriting a file with a ">"?

Options

  • Aset -o safe
  • Bset -o noglob
  • Cset -o noclobber
  • Dset -o append
  • Eset -o nooverwrite

How the community answered

(13 responses)
  • B
    8% (1)
  • C
    85% (11)
  • E
    8% (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 bash set -o options; 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

#noclobber#bash options#file protection#set command

Community Discussion

No community discussion yet for this question.

Full 102-500 Practice