Wildcards and Regular Expression Language Issues in Linux

In the process of using ls /usr/sbin/[AZ]* today, I found that the files starting with lowercase are also listed, as follows:

/usr/sbin/biosdecode                  /usr/sbin/pm-suspend
/usr/sbin/brctl                       /usr/sbin/pm-suspend-hybrid
/usr/sbin/build-locale-archive        /usr/sbin/postalias
/usr/sbin/cacertdir_rehash            /usr/sbin/postcat
/usr/sbin/capsh                       /usr/sbin/postconf

 After doing a bit of work, it turned out to be a language family problem. I found that the language family is zh_CN.gb2312, and the language family is changed to C.

 As we all know, there are only 0 and 1 in the computer, and the characters in the computer are all obtained from the encoding conversion table. Due to the different language encodings, the data selection results will be different. The output for C language and zh_CN is:

 When LANG=C, 0 1 2 3 4 ... abc .... ABC

 When LANG=zh_CN, 0 1 2 3 4... a A b B c C....

 Therefore, when you wildcard real [az], the range is a A b B .... Of course, lowercase characters will also be selected.

 

 But when testing regular expressions, although the language is zh_CN, the above problem will not occur. But when I read "Brother Bird Linux", it said to use regular expressions, but also pay attention to the language problem. I have tested it, and there is no problem. The test is as follows:

Text content: cat hello.txt
aaaaaaaa
Bbbbbbbb
cccccccc
11111111

Get content command:
grep -n "^[a-z]" hello.txt
1:aaaaaaaa
3:cccccccc

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326046832&siteId=291194637