Linux Administration
medium
Questão de Linux Administration #019e3987
Enunciado da Questão
Linux Administration
#redirection
#here-string
#stdin
#stdout
#bash-operators
Médio
Which of the following are valid stream redirection operators within Bash? (Choose THREE correct answers.)
A
<
Correta
B
<<<
Correta
C
Correta
D
E
%>
Explicação Oficial / Explicações da Comunidade
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.txtmakes the command read fromfile.txtinstead 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.txtwrites the command's output tofile.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.,%1to refer to job number 1) or in pattern matching. Using%>will result in an error.