4

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

For example

cat << abc.txt
1

1 Answer 1

7

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

9
  • I personnaly still don't understand Commented Feb 10, 2014 at 8:54
  • @Kiwy What is it that you don't understand? Commented Feb 10, 2014 at 8:55
  • Well reading it third time I start to understand you should express it as a end of input delimiter instead it would be way more clear than writing some script and explaining after. Commented Feb 10, 2014 at 8:57
  • @devnull : so, << will act as input if i say grep "somestring" << filename.txt ...just asking to clear out my head on this!! Commented Feb 10, 2014 at 8:58
  • 1
    @NoobEditor You might want to refer to a couple of links added in the answer. Commented Feb 10, 2014 at 9:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.