If Statement | Shell Scripting
This is a multipart blog article series where I am going to explain the concepts of shell scripting and how to write a shell script in Linux, UNIX or Mac based systems. You can also follow this tutorial blog using windows but for that you have to install a bash from.
In this article we will see the syntax of if statement and different types of operators used for doing comparison in between two things using if condition.
If then syntax
if condition then statement fi
if condition then statement else statement fi
if condition then statement elif condition then statement else statement fi
- Integer comparison:
-eq: is equal to
-ne: is not equal to
-gt: is greater than
-ge: is greater than or equal to
-lt: is less than
-le: is less than or equal to
<: is less than
<=: is less than or equal to
>: is greater than
>=: is greater than or equal to
- String comparison:
=: is equal to
==: is equal to
!=: is not equal to
<: is less than, in ASCII alphabetical order
>: is greater than, in ASCII alphabetical order
-z: string is null, that is has zero length
So, this will give you a brief idea about if statements in shell scripting. Hope you liked it and learned something new from it.
If you have any doubt, question, quires related to this topic or just want to share something with me, then please feel free to contact me.