LFCS · 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. The set -o noclobber bash option prevents accidental overwriting of existing files using output redirection operators like > or >&.
Question
Options
- Aset -o safe
- Bset -o noglob
- Cset -o noclobber
- Dset -o append
- Eset -o nooverwrite
How the community answered
(31 responses)- B3% (1)
- C94% (29)
- E3% (1)
Why each option
The `set -o noclobber` bash option prevents accidental overwriting of existing files using output redirection operators like `>` or `>&`.
`safe` is not a standard bash option for preventing file overwriting.
`set -o noglob` disables pathname expansion (globbing), which is unrelated to file overwriting prevention.
The `set -o noclobber` command enables the `noclobber` shell option, which prevents the shell from overwriting an existing file using redirection operators like `>` or `>|` unless explicitly forced with `>|`. This protects against accidental data loss.
`append` is not a bash option for `set -o`; `>>` is an operator for appending to a file, but `set -o append` doesn't exist as a shell option.
`nooverwrite` is not a standard bash option for preventing file overwriting.
Concept tested: Bash shell options for file redirection safety
Source: https://linux.die.net/man/1/bash
Topics
Community Discussion
No community discussion yet for this question.