zha*_*nwu 5 bash regex globbing
在 bash 中,我试过
ls [a-z]*
Run Code Online (Sandbox Code Playgroud)
并期望列出所有文件名以小写字母开头的文件。但是为什么还显示名称以大写字母开头的文件?
>ls [a-z]*
D e
>
Run Code Online (Sandbox Code Playgroud)
如果需要,bash 版本:
bash --version GNU bash,版本 4.1.5(1)-release (i486-pc-linux-gnu) 版权所有 (C) 2009 Free Software Foundation, Inc. 许可证 GPLv3+:GNU GPL 版本 3 或更高版本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.
Run Code Online (Sandbox Code Playgroud)
它不是正则表达式,这正是令人困惑的地方。相反,它使用一个称为“globbing”的系统 - 请参阅:
$ man 7 glob
Run Code Online (Sandbox Code Playgroud)
您需要使用 [[:lower:]] 代替 [az],如下所示:
$ ls -d [[:lower:]]*
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8727 次 |
| 最近记录: |