Reputation: 105
can someone, please, explain is there any difference in two following examples?
First example
if [ command ]; then ... fi
Second example
if [ command ] then ... fi
Upvotes: 0
Views: 24
Reputation: 798706
The second is an error. There must be a command separator between the command passed to if
and the then
clause. The command separator does not have to be a semicolon (a newline is sufficient), but there must be one.
Upvotes: 1
Reputation: 29821
Your second example does not work unless you put then
into a new line. Using the semicolon allows you to put then
into the same line as if
. People argue which is more readable, it's just a matter of taste, no technical difference.
Upvotes: 1