linux – Bash Extended Globbing提供语法错误

前端之家收集整理的这篇文章主要介绍了linux – Bash Extended Globbing提供语法错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
谁能解释一下:
$bash
$shopt -s extglob
$ls *.(txt|doc)
bash: Syntax error near unexpected token `('
$shopt extglob
extglob         on

这是一个debian挤压安装.我期待extglob将括号解释为组的开头.

谢谢,

保罗

解决方法

因为extglob不起作用.你必须在模式列表的开头放置一个修饰符(在本例中为(txt | doc)),如下所示(来自man bash):
?(pattern-list)
                 Matches zero or one occurrence of the given patterns
          *(pattern-list)
                 Matches zero or more occurrences of the given patterns
          +(pattern-list)
                 Matches one or more occurrences of the given patterns
          @(pattern-list)
                 Matches one of the given patterns
          !(pattern-list)
                 Matches anything except one of the given patterns

具体来说,ls *.*(txt | doc)产生我猜你想要的行为.

原文链接:https://www.f2er.com/linux/399249.html

猜你在找的Linux相关文章