Semicolons superfluous at the end of a line in shell scripts?
In the special case of find, ;
is used to terminate commands invoked by -exec. See the answer of @kenorb to this question.
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>
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.
Single semicolons at the end of a line are superfluous, since the newline is also a command separator. case
specifically needs double semicolons at the end of the last command in each pattern block; see help case
for details.
@Opensourcebook-Amit
newlines equivalent to single semicolon ;
on terminal or in shell script.
See the below examples:
On terminal:
[root@server test]# ls;pwd;
On shell script:
[root@server test]# cat test4.sh
echo "Current UserName:"
whoami
echo -e "\nCurrent Date:";date;
[root@server test]#
But I am not agree with the comment that &
is equivalent to newline or single semicolon
&
is run commands in background also a command separator but not worked as semicolon or newline.