Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 621
ezequiel-garzon Avatar asked Nov 13 '22 15:11

ezequiel-garzon


1 Answers

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 */
like image 78
Gabe Avatar answered Dec 27 '22 00:12

Gabe