LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   quick newb question (https://www.linuxquestions.org/questions/linux-newbie-8/quick-newb-question-726602/)

cynicalpsycho 05-17-2009 01:04 PM

quick newb question
 
I know that >> appends to the bottom of a file...
but what does << do?
I've searched google, and found that google ignores special characters, and there're no entries in the man file or help files, that i could find...

forrestt 05-17-2009 01:11 PM

It sends the file on the right of the << as the input for the command.

HTH

Forrest

cynicalpsycho 05-17-2009 01:26 PM

Quote:

Originally Posted by forrestt (Post 3543821)
It sends the file on the right of the << as the input for the command.

HTH

Forrest

could you elaborate with an example?

Disillusionist 05-17-2009 01:29 PM

There are three standard file handles that you need to know about

stdin 0
stdout 1
stderr 2

Commands take input from stdin, send normal output to stdout and send error messages to stderr

< file sends the contents of file into stdin to be used by command xyz
<< file reads lines of input from the keyboard, until the message "file" is given.

> file or 1> file redirects the normal output to file (replacing the previous content if the file exists)
>> file or 1>> file redirects normal output to file (appending to the end of the file)

2> file redirects the error messages to file (replacing the previous content if the file exists)
2>> file redirects the error messages to file (appending to the end of the file)

2>&1 redirects the error messages to the address for stdout

Disillusionist 05-17-2009 01:45 PM

Quote:

Originally Posted by cynicalpsycho (Post 3543833)
could you elaborate with an example?

Code:

cat << EOF
This is an example of the use of <<

The input is read until you reach a line that just contains EOF.

It could be anything, but typically EOF is used ;)
EOF


colucix 05-17-2009 02:49 PM

The example from Disillusionist is a so-called "here document". If you want to fed a command with a simple string you can use a "here string" using the triple input redirection:
Code:

grep example <<< "A simple example"


All times are GMT -5. The time now is 01:32 AM.