What does the 'elif' keyword do in bash scripting?

0130

The elif keyword in Bash scripting is used to create a conditional statement that allows you to check multiple conditions in an if statement. It stands for "else if" and is used when you want to test another condition if the previous if condition is false.

Here's a basic example:

#!/bin/bash

echo "Enter a number: "
read number

if [ $number -lt 10 ]; then
    echo "The number is less than 10."
elif [ $number -eq 10 ]; then
    echo "The number is equal to 10."
else
    echo "The number is greater than 10."
fi

In this example, if the first condition ($number -lt 10) is false, the script checks the condition in the elif statement ($number -eq 10). If that is also false, it proceeds to the else block.

0 Comments

no data
Be the first to share your comment!