Originally Posted by duvalr
So if I go to my SUSE Linux and add a "/2" file then I will get the same false result, right? And if jlightner does same he will also?
Sorry for the dela in this reply - just got back from a week in Rhodes (lovely place btw.)
Yes, if you have a /2 file on an unix like system you will get the same thing, at least if youo are using bash as your shell (I'm not sure if all shells will expand regular expression filename patterns - some may only expand simple globbing - the * and ? special characters).
[root]# find /proc/scsi/qla2300 | grep -v /[0-9]
[root]# find /proc/scsi/qla2300 | grep -c /[0-9]
Why does the "-v" on the grep see the "3" file?
Because after the shell expands the regular expression pattern, the command is:
# find /proc/scsi/qla2300 | grep -v /2
The -v switch says exclude lines containing /2
, so /proc/scsi/qla2300/2 is not shown, but all others are.
And on the "-c" it's really counting the "/2" at the root? Then why does it display "/proc/scsi/qla2300/2"?
I'm not sure which command made this happen.
So, bottom line is "USE QUOTES"! Why does grep not force you to, give a syntax error when no quotes? If you can get 2 different results based on having a file with the same name at the root or not then that is a problem as i see it.
Yeah, it's generally a good idea. grep doesn't force anything, or even see the quotes. The shell interprets filename patterns before it passes the arguments to grep, so it's up to whoever is calling grep know to quote patterns which he shell might interpret so as to be sure that grep gets the proper arguments.
Incidentally, this insight is one of the items which I think is among the main "aha" moments of using the shell - knowing that the shell expands some sorts of patterns before it passes them to programs.