bash – 如何在引用的表达式中转义扩展路径名扩展模式?
发布时间:2020-12-15 22:16:05 所属栏目:安全 来源:网络整理
导读:除了基本*,? […]模式,Bash shell提供扩展的模式匹配运算符,如!(pattern-list)(“匹配除了给定模式之外的所有模式”).需要将extglob shell选项设置为使用它们.一个例子: ~$mkdir test ; cd test ; touch file1 file2 file3~/test$echo *file1 file2 file3
除了基本*,? […]模式,Bash shell提供扩展的模式匹配运算符,如!(pattern-list)(“匹配除了给定模式之外的所有模式”).需要将extglob shell选项设置为使用它们.一个例子:
~$mkdir test ; cd test ; touch file1 file2 file3 ~/test$echo * file1 file2 file3 ~/test$shopt -s extglob # make sure extglob is set ~/test$echo !(file2) file1 file3 如果我将shell表达式传递给在子shell中执行它的程序,则运算符会导致错误.这是一个直接运行子shell的测试(这里我从另一个目录执行以确保不会过早地进行扩展): ~/test$cd .. ~$bash -c "cd test ; echo *" file1 file2 file3 ~$bash -c "cd test ; echo !(file2)" # expected output: file1 file3 bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `cd test ; echo !(file2)' 我已经尝试过各种各样的逃避,但我没想到的任何东西都能正常工作.我还怀疑extglob没有设置在子shell中,但事实并非如此: ~$bash -c "shopt -s extglob ; cd test ; echo !(file2)" bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `cd test ; echo !(file2)' 任何解决方案升值 解决方法$bash -O extglob -c 'echo !(file2)' file1 file3 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angular 结合 css 用图片自定义radio及checkbox样式
- 如何调用服务方法从ng的变化的select在angularjs?
- scala – spark sql没有正确转换时区
- yum 安装 webmin
- scala – 如何将数据集[(String,Seq [String])]转换为数据集
- teamcity和docker集成
- Bootstrap WPF Style
- AngularJS UI-Router:获取带有参数的状态的绝对URL
- anglejs – Angular ng-animate 1.3.*导致ng-class内部指令
- scala – 功能编程:Curry&Fold – 什么是词源?