2016-11-20 111 views
3

以下是似乎向我暗示bash中的一个错误的所有步骤。Bash字符类参数扩展不一致的行为

版本和平台信息

--> cat /etc/os-release 
NAME="Ubuntu" 
VERSION="14.04.5 LTS, Trusty Tahr" 
ID=ubuntu 
ID_LIKE=debian 
PRETTY_NAME="Ubuntu 14.04.5 LTS" 
VERSION_ID="14.04" 
HOME_URL="http://www.ubuntu.com/" 
SUPPORT_URL="http://help.ubuntu.com/" 
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" 
--> bash --version 
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) 
Copyright (C) 2013 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 

This is free software; you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. 

问题的详细步骤:

--> ls 
--> touch a aa aaa b bb bbb 
--> ls *[:alpha:] 
a aa aaa 
--> rm a aa aaa 
--> ls *[:alpha:] 
ls: cannot access *[:alpha:]: No such file or directory 

为什么会 '* [:阿尔法:]' 列表 'A *' 文件名,而不是 'B *'那些?

对于那些想知道,为了得到正确的行为,必须使用*([[:alpha:]])。但是这并不能解释这里显示的不一致。

回答

4

没有不一致。删除重复字符后,[:alpha:]相当于[:alph]。 等ls *[:alpha:]是真的等于ls *[:alph],只有a,aaaaa匹配,所以这就是你得到的输出。 删除这些文件后, ls *[:alph]将找不到匹配项,因此会收到错误。

如果要使用[:alpha:]字符等级,请使用[[:alpha:]]

+0

啊,谢谢你的回答。 – Fireplume