What is the real world use of input redirector (<)

The exercise for the input redirection is not very forthcoming on how we would use “<” in the real world.

The lesson consists of us typing cat < lakes.txt but this gives us the same output as cat lakes.txt.

The remainder of the lessons repeatedly uses the pipe(|) and output carat(>) but I have yet to come across one using the (<) for input again.

Any ideas where the input carat will come in handy?

https://www.codecademy.com/courses/learn-the-command-line/lessons/redirection/exercises/redirecting-stdin

Bash commands like cat can take filenames as input, and most of those can also take input from a stream.

An input stream is created with the symbol < and then a filename.
The difference between a filename and an input stream is that for a filename, you aren’t giving the command any actual input, just the name of a file, which the bash command then goes and reads.

If you give the command an input stream (like cat < lakes.txt), you are directly giving the command specific input, instead of a filename.

When you give the command specific data, the command has no idea where the input came from. Some commands can have noticeable differences, like the wc command (counts the number of lines, words, and characters), which usually outputs something like 5 60 372 filename.txt, will output 5 60 372 instead, since it doesn’t know where the input came from.

As for the use of the < symbol, I can’t think of an actual use off the top of my head. The people who created bash probably added use for the > symbol (which actually has very helpful uses), and decided to add the < symbol, just as the “opposite” of the > symbol.

I hope this helps!
Tiger_The_Cat

1 Like

Now that I think about it, there are some potential uses for the input redirector.

Some commands (like cowsay) are meant to take strings as input, not filenames. This might include a command that creates users, and wants a name for the user as a string. The < symbol allows us to give it a preexisting string from a file.

This could be helpful if we had lots of users to create, and we don’t want to name them all.
Instead of makenewuser "Bob", and then makenewuser "Joe", and so on, we could just say makenewuser < employees.txt.

1 Like