bash:反向(即非)shell通配符扩展? [英] bash: Inverse (ie. NOT) shell wildcard expansion?

查看:92
本文介绍了bash:反向(即非)shell通配符扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以处理反bash v4 shell扩展,即.对待所有文件不像通配符?在这种情况下,我需要rm所有不是'Folder-???'格式的文件,并且想知道是否有比做一个短的(即内置的)方式

Is there a way of handling invers bash v4 shell expansion, ie. treat all files NOT like a wildcard? I need to rm all files that are not of the format 'Folder-???' in this case and was wondering if there is a shorter (ie. built-in) way then doing a

for file in *
do
  [[ $i =~ \Folder-...\ ]] && rm '$i'
done

循环. (该示例不起作用,顺便说一句...)

loop. (the example doesn't work, btw...)

刚从bash学习好奇心...

Just out of bash learning curiosity...

推荐答案

shopt -s extglob
rm -- !(Folder-???)

这篇关于bash:反向(即非)shell通配符扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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