.
Previous Next

Interview Questions on Shell Script

21. Write code for if statement in shell script?

Syntax :-
if [ expression 1 ]
then
   Statement(s) to be executed if expression 1 is true
   Statement(s) to be executed if no expression is true
fi

22. Write if else code in shell script?

Syntax :-
if [ expression 1 ]
then
   Statement(s) to be executed if expression 1 is true
elif [ expression 2 ]
then
   Statement(s) to be executed if expression 2 is true
else
   Statement(s) to be executed if no expression is true
fi

23. Write switch statement code in shellscript?

Syntax :- 
case word in
  pattern1)
     Statement(s) to be executed if pattern1 matches
     ;;
  pattern2)
     Statement(s) to be executed if pattern2 matches
     ;;
  pattern3)
     Statement(s) to be executed if pattern3 matches
     ;;
esac

24. How to write while loop in shelscript?

while command
do
   Statement(s) to be executed if command is true
done

25. How to write for loop?

for var in word1 word2 ... wordN
do
   Statement(s) to be executed for every word.
done

Previous Next