Semicolons superfluous at the end of a line in shell scripts?

后端 未结 5 949
鱼传尺愫
鱼传尺愫 2020-12-12 20:07

I have a shell script which contains the following:

case $1 in
    0 )
    echo $1 = 0;
    OUTPUT=3;;
    1 )
    echo $1 = 1;
    OUTPUT=4;;
    2 )
    ec         


        
5条回答
  •  情歌与酒
    2020-12-12 20:30

    According to man bash:

      metacharacter
             A character that, when unquoted, separates words.  One of the following:
             |  & ; ( ) < > space tab
      control operator
             A token that performs a control function.  It is one of the following symbols:
             || & && ; ;; ( ) | |& 
    

    So, the ; can be metacharacter or control operator, while the ;; is always a control operator (in case command).

    In your particular code, all ; at the end of line are not needed. The ;; is needed however.

提交回复
热议问题