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

I have a shell script that contains the following:

case $1 in 0 ) echo $1 = 0; OUTPUT=3;; 1 ) echo $1 = 1; OUTPUT=4;; 2 ) echo $1 = 2; OUTPUT=4;; esac HID=$2; BUNCH=16; LR=.008; 

Are semicolons completely redundant in the snippet above? And is there any reason for some people using double semicolons?

It seems that semicolons are just a separator that you would use instead of a new line.

+89
syntax bash shell semicolon
Sep 21 2018-11-21T00:
source share
4 answers

Single semicolons at the end of a line are redundant since the new line is also a command delimiter. case in particular, requires a double semicolon at the end of the last command in each block of templates; see help case for more details.

+133
Sep 21 '11 at 21:45
source share

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: || & && ; ;; ( ) | |& <newline> 

Thus ; may be a metacharacter or control operator, and ;; It is always the managing operator (in the case of a command).

Everything in your specific code ; at the end of the line are not needed. Required ;; .

+27
Sep 21 2018-11-21T00:
source share

In the particular case of find; used to complete commands called by -exec. See @kenorb's answer to this question .

+4
Aug 05 '15 at 7:41
source share

@ Ignacio Vasquez-Abrams

In fact, this is not entirely accurate, single semicolons at the end of lines are not superfluous, and certainly not the same as new lines.

From the Bash Reference Guide

Commands separated by '; performed sequentially; the shell waits for each command to complete in turn. The returned status is the exit status of the last command executed.

Commands separated by a "new line" can be executed in parallel when commands separated by a semicolon are always executed sequentially

-one
Aug 19 '16 at 15:55
source share



All Articles