Inside a script you want to feed several lines of text that are written directly in the script, ending at a marker word, to a command's standard input. Which redirection operator introduces that construct?
LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium
Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.
It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.
The options
Not correct >>
Wrong. >> is output redirection that appends to a file. It concerns standard output, not standard input.
Not correct <<<
Wrong for multiple lines. <<< is a here-string, which feeds one single string to standard input, as in `grep root <<< "$line"`.
Not correct <
Wrong. < redirects standard input from an existing FILE; it cannot take text written inline in the script.
Correct <<
Correct. << starts a here-document: everything up to the line containing the delimiter word becomes the command's standard input.
Why
A here-document looks like `cat <<EOF` followed by the text and a line containing only EOF. Variables and command substitution are expanded inside it unless you quote the delimiter (<<'EOF'), and the <<- variant lets you indent both the body and the closing delimiter with TAB characters. The related <<< is a here-string for a single line.
Where this comes from
- Cited
- LPI exam objective 103.4
- What it says
- Use here-documents to supply inline text as standard input.
Practise this
Reading one question is not practice. The trainer will draw a set from objective 103 and space the ones you get wrong.