0

我有一个练习,我必须打印当前目录中的所有文件,这些文件以字母开头[a-z],或者以任意数量的结尾:[1/3/5/7/9]

因为我认为它必须是 globstyle ......并且代码是:

ls a[-z]* || *[13579]

但由于某种原因,这不起作用。也许我应该使用扩展正则表达式?

4

2 回答 2

2

The arguments to your ls command are not regular expressions at all but shell globs. And shell globs are interpreted by the shell before the command is executed. You can do:

ls [a-z]* *[13579]

Note that this may contain duplicated (file a1 will be listed twice) so you can do:

ls [a-z]* *[13579] | sort | uniq
于 2012-12-22T15:57:00.100 回答
0

尝试这样做:

printf '%s\n' [0-9]* *[a-z]

仅使用globs

http://mywiki.wooledge.org/glob

于 2012-12-22T16:32:04.357 回答