< and << in UNIX /Linux
16,333
<
is used to redirect input. Saying
command < file
executes command
with file
as input.
The <<
syntax is referred to as a here document. The string following <<
is a delimiter indicating the start and end of the here document.
$ cat abc.txt
cat: abc.txt: No such file or directory
$ cat << abc.txt
> Hello!
> Hey :)
> abc.txt
Hello!
Hey :)
$
<<
doesn't indicate any sort of indirection.
You might also want to refer to redirection and here document.
Related videos on Youtube
Author by
NoobEditor
Apparently, I prefer to keep an air of mystery about me..... bug in at -> so [dot] noobeditor [at] gmail [dot] com to solve the mystery!
Updated on September 18, 2022Comments
-
NoobEditor over 1 year
What are the operators
<<
and<
used for in Linux?For example
cat << abc.txt
-
Seapanther over 10 yearsRelated question: Correct textual name for <<
-
-
S edwards over 10 yearsI personnaly still don't understand
-
devnull over 10 years@Kiwy What is it that you don't understand?
-
NoobEditor over 10 years@devnull : so,
<<
will act as input if i say grep"somestring" << filename.txt
...just asking to clear out my head on this!! -
devnull over 10 years@NoobEditor In your example,
filename.txt
would be treated as a delimiter. Nothing would be read from the file. -
devnull over 10 years@Kiwy I rephrased the answer. Hope it's more clear now.
-
S edwards over 10 yearsI see that. that's better ;-)
-
NoobEditor over 10 years@devnull : ok..its pretty clear, upvoted...and accepted ( but if some1 else comes up with better answer then u have competition )...can u give me some reference urls where i can see both of these commands in work????
-
devnull over 10 years@NoobEditor You might want to refer to a couple of links added in the answer.