Use a File As Input for a Command


<

Normally your keyboard provides input to commands, so it is termed stdin. In the same way that you can redirect stdout to a file, you can redirect stdin so it comes from a file instead of a keyboard. Why is this handy? Some commands can't open files directly, and in those cases, the < (lesser than) is just what you need.

For instance, normally the echo command repeats what you type on stdin, as shown here:

$ echo "This will be repeated" This will be repeated. 


However, you can use the < to redirect input, and the echo command uses the contents of a file instead of stdin. In this case, let's use the hank_mobley.txt file created in the previous section.

$ echo < hank_mobley.txt Mon Nov 21 21:33:58 CST 2005 1958_Peckin_Time/ 1960_Roll_Call/ 1960_Soul_Station/ 1961_Workout/ 1963_No_Room_For_Squares/ 


You're not going to use the < all the time, but it will be exactly what you need in a number of situations, so keep it in mind.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net