linux – Bash Extended Globbing提供语法错误

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

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

谢谢,

保罗

解决方法

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

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

猜你在找的Linux相关文章