为什么 shell case 语句中的第一个模式不能是多重模式?

发布于 2024-12-12 10:19:30 字数 542 浏览 0 评论 0原文

案例标准描述声明说:

The format for the case construct is as follows:

case word in
  [(]pattern1) compound-list;;
  [[(]pattern[ | pattern] ... ) compound-list;;] ...
  [[(]pattern[ | pattern] ... ) compound-list]
esac

The ";;" is optional for the last compound-list.

为什么 pattern1 不能也是多重模式?这看起来相当随意,尽管我很确定它一定不是这样。

谢谢!

The standard description of the case statement says:

The format for the case construct is as follows:

case word in
  [(]pattern1) compound-list;;
  [[(]pattern[ | pattern] ... ) compound-list;;] ...
  [[(]pattern[ | pattern] ... ) compound-list]
esac

The ";;" is optional for the last compound-list.

Why can't be pattern1 be a multiple pattern as well? It seems rather arbitrary, though I'm pretty sure it must not be.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒数 2024-12-19 10:19:30

我认为你误解了他们的意思。您链接到的页面上的语法没有显示这样的区别:

case_clause      : Case WORD linebreak in linebreak case_list    Esac
                 | Case WORD linebreak in linebreak case_list_ns Esac
                 | Case WORD linebreak in linebreak              Esac
                 ;
case_list_ns     : case_list case_item_ns
                 |           case_item_ns
                 ;
case_list        : case_list case_item
                 |           case_item
                 ;
case_item_ns     :     pattern ')'               linebreak
                 |     pattern ')' compound_list linebreak
                 | '(' pattern ')'               linebreak
                 | '(' pattern ')' compound_list linebreak
                 ;
case_item        :     pattern ')' linebreak     DSEMI linebreak
                 |     pattern ')' compound_list DSEMI linebreak
                 | '(' pattern ')' linebreak     DSEMI linebreak
                 | '(' pattern ')' compound_list DSEMI linebreak
                 ;
pattern          :             WORD         /* Apply rule 4 */
                 | pattern '|' WORD         /* Do not apply rule 4 */

I think you're misinterpreting what they're saying. The grammar on the page you link to does not show such a distinction:

case_clause      : Case WORD linebreak in linebreak case_list    Esac
                 | Case WORD linebreak in linebreak case_list_ns Esac
                 | Case WORD linebreak in linebreak              Esac
                 ;
case_list_ns     : case_list case_item_ns
                 |           case_item_ns
                 ;
case_list        : case_list case_item
                 |           case_item
                 ;
case_item_ns     :     pattern ')'               linebreak
                 |     pattern ')' compound_list linebreak
                 | '(' pattern ')'               linebreak
                 | '(' pattern ')' compound_list linebreak
                 ;
case_item        :     pattern ')' linebreak     DSEMI linebreak
                 |     pattern ')' compound_list DSEMI linebreak
                 | '(' pattern ')' linebreak     DSEMI linebreak
                 | '(' pattern ')' compound_list DSEMI linebreak
                 ;
pattern          :             WORD         /* Apply rule 4 */
                 | pattern '|' WORD         /* Do not apply rule 4 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文