Reputation: 19
Can someone please explain the behavior of grep for the below case:
$ grep <html> foo
$ bash: html: No such file or directory
Upvotes: 1
Views: 95
Reputation: 26447
$ grep <html> foo
is
$ cat html | grep > foo
which reads the file html
sends it to grep and stores the result in a file called foo. See hurb's answer for an extended explanation
Upvotes: 0
Reputation: 2217
You need to escape <
and >
inside bash.
Correct syntax:
grep '<html>' myfile
grep \<html\> myfile
Further information:
<
and >
are used for I/O Redirection. <
accepts input and >
redirects your output. Thus, grep <html> foo
tries to read the file named html
and redirects the output into the file myfile
.
Upvotes: 1