Conditional statment practical


Q. Conditional statements को दर्शाने के लिये शैल programming लिखिये।
Ans.
Bash में निम्लिखित कंडीशनल स्टेटमेंट्स है -

<![if !supportLists]> 1)      <![endif]> if..then..fi statement (Simple If)
<![if !supportLists]> 2)      <![endif]> if..then..else..fi statement (If-Else)
<![if !supportLists]> 3)      <![endif]> if..elif..else..fi statement (Else If ladder)
<![if !supportLists]> 4)      <![endif]> if..then..else..if..then..fi..fi..(Nested if)
 
<![if !supportLists]> 1)      <![endif]> Bash If..then..fi statement
Syntax:
if [ conditional expression ]
then
            statement1
            statement2
Fi
 
Example:





<![if !supportLists]> 2)      <![endif]> Bash If..then..else..fi statement
 
Syntax:
 
If [ conditional expression ]
then
            statement1
            statement2
else
            statement3
            statement4
Fi

Example:



<![if !supportLists]> 3)      <![endif]> Bash If..elif..else..fi
 
Syntax:
 
If [ conditional expression1 ]
then
            statement1
            statement2
elif [ conditional expression2 ]
then
            statement3
            statement4
else
            statement5
fi

Example:



<![if !supportLists]> 4)      <![endif]> Bash If..then..else..if..then..fi..fi..
 
Syntax:

If [ conditional expression1 ]
then
            statement1
            statement2
else
            if [ conditional expression2 ]
            then
                        statement3
fi
fi

Example:




More topics from Linux to read
LINUX
EasyExamNotes.com covered following topics in these notes.
LINUX solved questions