Basic Shell Commands

Go to Problems

Conditional Statements in bash

if-else statements allow us to make decisions in our Bash scripts. They allow us to decide whether or not to run a piece of code based upon conditions that we may set.

num=5
if [ $num -lt 0 ]; then
    echo "number is negative";
elif [ $num -lt 10 ]; then
    echo "number is less than 10";
else
    echo "number is equal or greater than 10";
fi

Serious about Learning Scripting ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum.
Shell scripting
Problem Score Companies Time Status
Valid phone number 150
22:24
Lines in a given range 200
27:49
Remove Punctuations 250
12:58
Transform CSV 300
19:07