[SATLUG] character classes with *
bruce.dubbs at gmail.com
Thu Oct 2 11:16:41 CDT 2014
> Bruce & Mike, the formatting of my first email was thrown off and kind of munged everything together. Below is what I was actually attempting to convey and what the actual contents of the test file was.
> Wes, cool tutorial. I'm not quite there yet with awk and sed, but I do like interpreting the escapes with special characters especially with using brackets in the file to make sure not to use character classes when searching for strings that have brackets in them.
> I am trying to understand why grep is behaving in this manner - using character classes without quotations with the asterisk.
> This just adds to my confusion:
> Earlier when I ran grep [abcde]* test ##which returned everything in the file
> grep [abcdef]* test ##which returned nothing
> I removed all files in that directory except for the test file, and grep [abcdef]* test then returned everything in the file!
> however, grep [a-z]* test still returns nothing at all.
> Perhaps just using brackets and a star without quotes is something that should never be done, I am just wanting to know the cause of this behavior, because, yknow, knowledge.
You need to use quotes to prevent bash from interpreting special
characters. For instance
will return all files that begin with a, b, and c.
See, for instance, http://tldp.org/LDP/abs/html/special-chars.html
More information about the SATLUG