Reputation: 13
I don't have clear how tu use < to redirect the stdin. What is the difference between using the command cat file.txt and cat < file.txt? With this example the output would be the content of file.txt. Can anyone use a better example to show how to use
Im studying command lines, and I saw this example for using <:
cat < file.txt
But I don't see good with this example the purpose of <.
cat < file.txt
I would like somebody to explain how to use < and an example because I still haven't finded a good explanation of the use of <.
I found an example that I find very useful and clear about the use of < in a forum, but would like to know if its 100% correct:
You want to know why do we use ‘<’ if we can cat file.txt (rather than cat < file.txt).
When you ‘cat file.txt’ with content 1, 2, 3, it prints 1, 2, 3. If you have a file abc with a function “def abc(x, y, z)” and you want to test the function with inputs 1, 2, 3 (pass 1, 2, 3 values to variables x, y, z ) that are stored in file.txt. you can use “cat abc < file.txt” instead of type 1, 2, 3.
Upvotes: 1
Views: 2192
Reputation: 96
Welcome to SO!
In reality, those two examples, cat file.txt
and cat < file.txt
are exactly the same.
The use of ">" shows up when you want to add text to another file. For example, cat > file2.txt < file.txt
. In there, the content of file.txt goes to file2.txt. If you didn't add the < file.txt
you would have to write down the content.
Hope I helped, if you have more questions, don't doubt to ask them!
Upvotes: 2