< 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.

Share:
16,333

Related videos on Youtube

NoobEditor
Author by

NoobEditor

Apparently, I prefer to keep an air of mystery about me..... bug in at -&gt; so [dot] noobeditor [at] gmail [dot] com to solve the mystery!

Updated on September 18, 2022

Comments

  • NoobEditor
    NoobEditor over 1 year

    What are the operators <<and < used for in Linux?

    For example

    cat << abc.txt
    
  • S edwards
    S edwards over 10 years
    I personnaly still don't understand
  • devnull
    devnull over 10 years
    @Kiwy What is it that you don't understand?
  • NoobEditor
    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
    devnull over 10 years
    @NoobEditor In your example, filename.txt would be treated as a delimiter. Nothing would be read from the file.
  • devnull
    devnull over 10 years
    @Kiwy I rephrased the answer. Hope it's more clear now.
  • S edwards
    S edwards over 10 years
    I see that. that's better ;-)
  • NoobEditor
    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
    devnull over 10 years
    @NoobEditor You might want to refer to a couple of links added in the answer.