[A-Z] 和 [:upper:]的不同?(locale 对字符排序的影响)

[A-Z] 和 [:upper:]的不同?(locale 对字符排序的影响)

复制内容到剪贴板
代码:
[No.593 20:24:01 tmp ]# echo "aA" | grep '[A-Z]$'
aA
[B][No.594 20:24:14 tmp ]# echo "aA" | grep '[a-z]$'
aA[/B]

[No.595 20:24:20 tmp ]# echo "aA" | grep '[[:upper:]]$'
aA
[B][No.596 20:25:08 tmp ]# echo "aA" | grep '[[:lower:]]$'
[No.597 20:25:18 tmp ]#
[/B]
[No.597 20:25:18 tmp ]# bash -version
GNU bash, version 3.00.16(1)-release (i386-pc-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.


[No.598 20:29:27 tmp ]# uname -a
Linux ubuntu 2.6.10huan #1 Mon Oct 17 12:49:37 CST 2005 i686 GNU/Linux
这算什么毛病?      
[QUOTE=li-jiahuan]
复制内容到剪贴板
代码:
[No.593 20:24:01 tmp ]# echo "aA" | grep '[A-Z]$'
aA
[B][No.594 20:24:14 tmp ]# echo "aA" | grep '[a-z]$'
aA[/B]

[No.595 20:24:20 tmp ]# echo "aA" | grep '[[:upper:]]$'
aA
[B][No.596 20:25:08 tmp ]# echo "aA" | grep '[[:lower:]]$'
[No.597 20:25:18 tmp ]#
[/B]
[No.597 20:25:18 tmp ]# bash -version
GNU bash, version 3.00.16(1)-release (i386-pc-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.


[No.598 20:29:27 tmp ]# uname -a
Linux ubuntu 2.6.10huan #1 Mon Oct 17 12:49:37 CST 2005 i686 GNU/Linux
这算什么毛病?[/QUOTE]
见鬼了?      
dearvoid,是何解啊?      
不晓得, 解释不了 你确信这是你的执行结果吗?      
我确信!
不过就只有在我机器上时我才确信
我在CentOS4里也试了
同样结果
不过在其它机器上当然是……等同的
我机器真可能见鬼了      
我也试了,同样!      
my results:
引用:
-(user@host:tty)-(tmp)-
[361 0] % echo "aA" | grep '[A-Z]$'
aA
-(user@host:tty)-(tmp)-
[361 0] % echo "aA" | grep '[a-z]$'
-(user@host:tty)-(tmp)-
[361 1] % echo "aA" | grep '[[:upper:]]$'
aA
-(user@host:tty)-(tmp)-
[361 0] % echo "aA" | grep '[[:lower:]]$'
-(user@host:tty)-(tmp)-
[361 1] % bash --version
GNU bash, version 3.00.16(5)-release (powerpc-apple-darwin7.7.0)
Copyright (C) 2004 Free Software Foundation, Inc.
-(user@host:tty)-(tmp)-
[361 0] % uname -a
Darwin apple.local 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh powerpc
-(user@host:tty)-(tmp)-
[361 0] % grep -V
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-(user@host:tty)-(tmp)-
[361 0] %


      
[QUOTE=TUDOU01]我也试了,同样![/QUOTE]

兄弟哪个系统?      
我也是这样的. 但是用了grep -o后就没有输出, 说明实际没有匹配到.      
今日偶得, 献给欢欢
引用:
-(user@host:tty)-(tmp)-
[3836 0] $ man grep
......

REGULAR EXPRESSIONS
    ......

    Within a bracket expression, a range expression consists of two charac-
    ters 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 dictio-
    nary  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.
......

-(user@host:tty)-(tmp)-
[3836 0] $ cat file
a
A
z
Z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=en_US.UTF-8 grep [a-z] file
a
A
z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=en_US.UTF-8 grep [A-Z] file
A
z
Z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=C grep [a-z] file
a
z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=C grep [A-Z] file
A
Z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=en_US.UTF-8 sort file
a
A
z
Z
-(user@host:tty)-(tmp)-
[3836 0] $ LC_ALL=C sort file
A
Z
a
z
-(user@host:tty)-(tmp)-
[3836 0] $