Programming Tutorials

(追記) (追記ここまで)

Nested if-else-fi in Linux Shell Script

By: Dorris in Linux Tutorials on 2011年01月15日 [フレーム]

In Linux Shell Script, we can use nested if-else-fi statements to execute a set of statements based on multiple conditions.

Here is an example of nested if-else-fi in Linux Shell Script:

#!/bin/bash
a=10
b=20
if [ $a == $b ]
then
 echo "a is equal to b"
else
 if [ $a -gt $b ]
 then
 echo "a is greater than b"
 else
 echo "a is less than b"
 fi
fi

In this example, we first check if the variable a is equal to b. If not, we use a nested if-else-fi statement to check if a is greater than b or less than b and output the appropriate message.

Note that the inner if-else-fi statement must be enclosed in a pair of else and fi statements from the outer if-else-fi statement.




(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)

(追記) (追記ここまで)
(追記) (追記ここまで)

Related Tutorials

AltStyle によって変換されたページ (->オリジナル) /