[英]How to match file extensions regardless of case in bash script
Let's just say i want to match the .abc
extension but it could come over as .ABC
or .AbC
. 我只想说我想匹配.abc
扩展名,但它可能会以.ABC
或.AbC
。 How can I identify all of these variations of the .abc
extension in order to process .abc
files? 如何识别.abc
扩展名的所有这些变体以处理.abc
文件?
Right now i'm using: 现在我正在使用:
ls | grep -i .abc
but i've heard that piping to grep is usually not the best idea. 但是我听说grep的管道通常不是最好的主意。 Is there a better way to do this? 有一个更好的方法吗?
If you enter the extension literally, you can use character classes: 如果从字面上输入扩展名,则可以使用字符类:
ls *.[Aa][Bb][Cc]
You can also use the -iname
option of find
: 您还可以使用find
的-iname
选项:
find -maxdepth 1 -iname '*.abc'
You can use the nocaseglob
option to the shopt
builtin to make globs not pay attention to case. 你可以使用nocaseglob
选项购买内置的shopt
,使globs不注意大小写。
$ touch foo.abc foo.ABC
$ echo *.abc
foo.abc
$ shopt -s nocaseglob
$ echo *.abc
foo.ABC foo.abc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.