Why can't the first pattern in a shell case statement be a multiple pattern?

放肆的年华 提交于 2019-12-03 20:58:00

问题


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!


回答1:


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 */


来源:https://stackoverflow.com/questions/7947703/why-cant-the-first-pattern-in-a-shell-case-statement-be-a-multiple-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!