Types of Input Redirection
■ Standard Input (stdin)
■ Basic Input Redirection < ■ Here-document Redirection << ■ Here-string Redirection <<<
Standard Input (stdin)
■ Standard input is the default way a program receives input
■ Standard input usually comes from the keyboard
The cat command without redirection __________
waits for additional input
What is CTRL-D is used for?
signal the end-of-file (EOF) through stdin
Basic Input Redirection <
< operator is used to redirect input from a file
r feeds pre-written data into a command automatically
cat < myfile.txt
displays the contents of myfile.txt
mail -s “I Love Linux” support@diontraining.com < message.txt
uses message.txt as the body of an email
Here-document Redirection «
known as a here-document
■ Allows embedding multi-line input directly in a command
■ Requires a delimiter to mark the start and end of the text block
«_space;Example
cat «EOF
This is the first line. This is the second line. EOF
Here-string Redirection «<
known as a here-string
Allows passing a single string as input to a command
Example
mysql -u admin -p «< “DROP DATABASE IF EXISTS testdb; CREATE DATABASE testdb; USE testdb; SOURCE /path/to/setup.sql;”