In this article, we will see how to user IF statements within a bash shell script in Linux.
In bash shell, when we need to check a condition to execute particular code block, IF and IF else statements can be used. It eveluates It evaluates an expression to decide whether to perform a code.
Lets look to its syntax.
if [ "x" = "x" ]; then
echo "true"
else
echo "false"
fi
Lets see it in bash shell scripting example.
As above output indicates, we added a basic IF statement to a shell bash script with name "1.sh". Our script takes 1 parameter from shell call. If parameter is "1", it confirms it with IF check. Any parameter not "1" results with ELSE block to be executed.