The example given for the use of input redirection here:
cat < lakes.txt
Doesn’t seem particularly helpful since is does the same thing as
cat lakes.txt. Please share a case where the use of input redirection,
<, makes an important contribution.
There’s redundancy in the above example because most of the built-in functions that we would want to use in redirecting input,
sort for example, already directly accept files as input. So we won’t get any added benefit from using
<. However, if a function is designed to simply read from the standard input, then
< helps us out.
Let me be more explicit. Suppose you write a function which expects some user input. The typical ways that we do this in a programming language reads directly from
stdin. It’s tedious to test or interface with this function completely through the standard input. So we may either write a collection of test input in a file or aggregate real input to this program in a file, prior to calling the function. How do we then make the program believe that it’s reading from
stdin while it’s actually reading from the file we made? We accomplish this by using
< where on the left side, we have our (executable) program and on the right we have the file we created. In this way, we pass all of the input to the function at once. This proves to be extremely handy in testing and interacting with programs in the command line.