参考文章如下,非常的详细,想了解来龙去脉的可以直接查看这个文章
参考文章链接
问题描述:
在自己练习通配符使用时发现[a-z],[A-Z]并不能准确匹配,而是大小写的文件都进行了匹配 ![问题表现](https://img-blog.csdnimg.cn/997adf48a3e14cbaa9e00bcc1a554c1d.png#pic_center)原因分析:
CentOS 4 时就有人反应这个问题了:0001511: bash shell produces incorrect results for regular expression [A-Z]*。Bug 回复里有人提到《Bash beginner’s guide》 里 Chapter 4. Regular expressions 对此有说明:然后查看了我的本地locale环境变量 ![区域环境变量](https://img-blog.csdnimg.cn/e101181d452e46b984076ca1803f64de.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAc2hhbuWKoOaKiuWKsg==,size_11,color_FFFFFF,t_70,g_se,x_16#pic_center)Within a bracket expression, a range expression consists of two characters separated by a hyphen. It matches any single character that sorts between the two characters, inclusive, using the locale’s collating sequence and character set. For example, in the default C locale, “[a-d]” is equivalent to “[abcd]”. Many locales sort characters in dictionary order, and in these locales “[a-d]” is typically not equivalent to “[abcd]”; it might be equivalent to “[aBbCcDd]”, for example. To obtain the traditional interpretation of bracket expressions, you can use the C locale by setting the LC_ALL environment variable to the value “C”.**