The if-else condition in shell script
If-else is a very important coding concept. Just like other programming languages, shell script uses if-else statements to solve problems.
If a condition is true, the algorithm performs a certain action; else, it performs something else.
Syntax
if [ condition ]
then
trueAction....
else
falseAction
fi
Code
The following code outputs “Yes” if the two numbers are equal and “No” if they are not.
var1=50var2=60if [ $var1 == $var2 ]thenecho "YES"elseecho "NO"fi
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved