2016-11-20 115 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