击运动风格的glob ...? [英] Bash exercise-glob style...?

查看:195
本文介绍了击运动风格的glob ...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个练习,在我所要打印在当前目录下的所有文件,这与字母开头 [AZ] ,或任意数量的结束这些: [1/3/5/7/9]

I have an exercise, in which I have to print all the files in the current directory, which start with the letter [a-z], or ending with any number of these: [1/3/5/7/9]

因为我认为它有可能成为globstyle ...和code是:

As I think it has to be in globstyle... and the code is:

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

但由于某种原因不能正常工作。
 也许我应该使用扩展的正前pressions?

but for some reason that doesn't work. maybe I should use Extended Regular Expressions?

推荐答案

该参数的ls命令是不是在所有,但shell通配符,正规的前pressions。和壳牌水珠是由shell PTED间$ P $的 的执行命令。你可以这样做:

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]

请注意,这可能包含重复(文件 A1 会列出两次),这样你可以这样做:

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

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

这篇关于击运动风格的glob ...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆