< |
Redirects input to a specified file. |
Redirecting input from a file. |
> |
Redirects output to a specified file. |
Redirecting command output to a file. |
>> |
Redirects output to be appended to the end of the specified
file. |
Redirecting command output to a file. |
2> |
Redirects error output to a specified file. |
Redirecting error output to a file. |
<<text |
Reads standard input until it encounters text. |
This is used in what is called a “here-document.” Input
is usually typed on the screen or in a shell script. For example,
this script creates a file called hello.c, compiles
it into hello, and then executes it:
echo "Creating program source..."
if cat > hello.c <<End_Of_File
main() {
puts("Hello, world!");
}
End_Of_File
then
echo "Compiling program..."
if make hello
then
echo "Executing program..."
exec ./hello
else
exit $? # make failed
fi
else
exit $? # cat failed
fi
When you run the shell script, it runs the cat > hello.c command
using the input between the two End_of_File strings. |