In bash, what is the difference between <, << and <<<?


I'm learning now to tinker with bash (Ubuntu Terminal) and I would like to understand the difference between these three operators.

I think < is related to files, but I can't explain what it does descriptively. I think it's to send the value of the file to the command to be executed.


cat < index.php
#Exibe o conteúdo do arquivo

When I use << , it keeps opening a new line, without executing the previous command (I don't understand what it does right).


cat <<

And the <<< seemed to be related to expressions.


cat <<< "O número é $((13 + 2))"
O número é 15
  • So in which case do I use < , << , or <<< ?

  • What is the purpose of each one?

  • What are they called?


< input redirection

For commands that wait for input (usually keyboard), you can redirect a file to the input (just like you did with cat < index.php ). Another example:

nc -l 8888 < /etc/fstab

<< String Input Redirection

It's the same thing, but instead of passing a file, you type the string directly (in multiple lines). You end the input with a CTRL + D , or like this:

cat << FIM
bla bla

Typically used to print messages on the screen with indentation.


I couldn't find a definition for it, but I use it as a redirector of the output of a command, as if it were an inverted pipe . Example:

grep -i label <<< cat /etc/fstab
Scroll to Top