Linux Administration
medium

Pregunta de Linux Administration #019e3987

Enunciado de la Pregunta
Linux Administration
#redirection
#here-string
#stdin
#stdout
#bash-operators
Medio

Which of the following are valid stream redirection operators within Bash? (Choose THREE correct answers.)

A

<

Correcto
B

<<<

Correcto
C
Correcto
D
E

%>

Explicación Oficial / Explicaciones de la Comunidad

In Bash, stream redirection operators are used to control where input and output of commands are directed. The valid operators among the options are <, <<<, and >.

How it Works

  • <: Redirects the contents of a file as standard input to a command. For example, command < file.txt makes the command read from file.txt instead of the keyboard.
  • <<<: Known as a "here string," it redirects a string as standard input to a command. For example, command <<< "string" passes the string as input.
  • >: Redirects standard output of a command to a file, overwriting the file if it exists. For example, command > file.txt writes the command's output to file.txt.

Why the Correct Values are Right

  • <: This is a standard input redirection operator defined in POSIX shells. It is widely used to feed file content into commands.
  • <<<: This is a Bash-specific operator (also available in some other shells like Zsh) that provides a convenient way to pass a string as input without using a temporary file or a here-document.
  • >: This is a standard output redirection operator. It is fundamental for saving command output to files.

Why the Incorrect Values are Wrong

  • >>>: This is not a valid redirection operator in Bash. The double greater-than sign >> is valid for appending output to a file, but triple >>> has no meaning and will cause a syntax error.
  • %>: This is not a valid redirection operator in Bash. The percent sign is not used in redirection syntax; it is used in job control (e.g., %1 to refer to job number 1) or in pattern matching. Using %> will result in an error.