加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – Bash Extended Globbing提供语法错误

发布时间:2020-12-13 17:03:49 所属栏目:Linux 来源:网络整理
导读:谁能解释一下: $bash$shopt -s extglob$ls *.(txt|doc)bash: syntax error near unexpected token `('$shopt extglobextglob on 这是一个debian挤压安装.我期待extglob将括号解释为组的开头. 谢谢, 保罗 解决方法 因为extglob不起作用.你必须在模式列表的开
谁能解释一下:
$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)产生我猜你想要的行为.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读