I saw this usage of redirection somewhere, and thought it was a typo:
grep root < /etc/passwd
But after I run it, I saw that it gives the same output with
grep root /etc/passwd:
$ grep root < /etc/passwd
root:x:0:0:root:/root:/bin/bash
$ grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
The same thing happens with
cat < /etc/passwd
cat /etc/passwd
However, redirection is ignored when used with ls:
ls < /etc/passwd
does not print the same output with
ls /etc/passwd
What is happening?
ls < /etc/passwdnot works for the same reason why neithercat /etc/passwd | lsworks. If you rungrep ''orcatfrom the command prompt (no input, no parameters), they will wait for you to enter the input from the keyboard. Butlswill not do that as it expects no input. – manatwork Sep 9 '11 at 10:31