Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?

That confusing snippet was changed in newer versions of GNU grep to:

-i, -ignore-case Ignore case distinctions, so that characters that differ only in case match each other.

See this commit: http://git.savannah.gnu.org/cgit/grep.git/commit/?id=e1ca01be48cb64e5eaa6b5b29910e7eea1719f91

 .BR \-i ", " \-\^\-ignore\-case
-Ignore case distinctions in both the
-.I PATTERN
-and the input files.
+Ignore case distinctions, so that characters that differ only in case
+match each other.

As to where the old formulation may originate, some programs like less(1) have a (mis)feature[1] where using an uppercase letter in a pattern will turn off case insensitivity for a particular search (override the -i flag). The author of that doc snippet probably assumed that many people expected that behavior, and instead of some direct caveat, preferred that non-committal sentence. FWIW, such a feature was never a part of ed(1), grep(1), vi(1), perl(1) etc. or of the regex(3) or pcre(3) APIs.

[1] that seems to have its origins in emacs, where it's the default; there you can turn it off by setting the (customizable) search-upper-case variable to nil.


Apparently I have a different manpage.

   -i, --ignore-case
          Ignore case distinctions, so that characters that differ only in
          case match each other.

In any case, it's not about the filenames.

It ignores case in the file (contents) but also in the pattern.

Test file:

___________
Hello World
^^^^^^^^^^^

Grep results (ignore case of file contents):

$ grep hello test.txt 

$ grep Hello test.txt 
Hello World
$ grep -i HELLO test.txt 
Hello World
$ grep -i hello test.txt 
Hello World

Grep results (ignore case of pattern):

$ grep [a-Z] test.txt 
grep: Invalid range end
$ grep -i [a-Z] test.txt
Hello World
$ grep -i [A-z] test.txt
Hello World
$ grep [A-z] test.txt
___________
Hello World
^^^^^^^^^^^

As you can see the results can sometimes be a little unexpected.

Not sure if there is an example where this actually matters more.


"It ignores case in the file (contents) but also in the pattern", this suggests (although it doesn't necessarily say it), that it is possible to ignore case in the pattern, but not in the contents.  I'd like to understand how this would work (ignoring pattern, but not contents -- or the other way around).

Well, for example, it could be written so that a pattern of “hello” would match “Hello” in the file, but not vice versa.  While this sounds hypothetical, it is the way spell-check works.  If your dictionary contains “stack” and “exchange”, and your document contains “Stack Exchange”, spell-check will succeed without error.  But if your dictionary contains “Unix” and your document contains “unix”, that will be flagged as an error.