ls使用通配符[a-z],[A-Z]匹配的结果不对

参考文章如下,非常的详细,想了解来龙去脉的可以直接查看这个文章
参考文章链接

问题描述:

在自己练习通配符使用时发现[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 对此有说明:

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”.**

然后查看了我的本地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)

解决方案:

因为LC_ALL和LANG优先级的关系:LC_ALL > LC_* >LANG ,所以直接改掉LC_ALL=C就可以了,当然我的语言环境也变回了英文。 export LC_ALL=C ![结果](https://img-blog.csdnimg.cn/a4b60df806654a8798bca027fcf7dab2.png#pic_center)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值