nerdexam
CompTIA

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 >>.

Shells, Scripting and Data Management

Question

Which of the following bash options will prevent an administrator 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

(22 responses)
  • A
    5% (1)
  • C
    91% (20)
  • D
    5% (1)

Why each option

The `set -o noclobber` option in bash prevents existing files from being accidentally overwritten by redirection operators like `>` and `>>`.

Aset -o safe

`set -o safe` is not a standard bash option.

Bset -o noglob

`set -o noglob` disables pathname expansion (globbing), meaning characters like `*`, `?`, and `[` are treated as literal characters, not for matching filenames.

Cset -o noclobberCorrect

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.

Dset -o append

`set -o append` is not a standard bash option for this purpose; `>>` is the append operator itself.

Eset -o nooverwrite

`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

#bash shell#redirection#file overwriting#noclobber

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice