Assignment No: 09
Assignment No: 09
Aim: To study, implement and practice conditional and looping statements, case statements
in Linux.
Objective: To study and learn about the different conditional and looping statements, case
statements in Linux.
Theory:
Conditional Statements | Shell Script
Conditional Statements: There are total 5 conditional statements which can be used in bash
programming
1. if statement
2. if-else statement
3. if..elif..else..fi statement (Else If ladder)
4. if..then..else..if..then..fi..fi..(Nested if)
5. switch statement
Practical:
Conditional statements in Linux:
1.) Write a shell program to check whether given number is even or odd.
Code:
Output:
2.) Write a shell script to determine the seller has profit or incurred loss and also determine
how much profit was made or loss may incurred if the cost price and selling price of the
product is entered through keyboard.
Code:
Output:
3.) Write a shell script to check whether the entered number is prime or not.
Code:
Output:
4.) Write a shell script to find the smallest and largest of three numbers.
Code:
Output:
5.) Write a shell program to find the gcd for the 2 given numbers.
Code:
Output:
Looping structures in Linux:
1.) Write a menu driven shell script which will print the following menu and find
a. Factorial of a number
b. Reverse of a number
c. Even / Odd
Code:
Output:
2.) Write a shell script to check entered string is palindrome or not.
Code:
Output:
3.) Write a shell program to reverse the digits of five digit integer.
Code:
Output:
4.) Write a shell script to display the digits which are in odd position in a given 5 digit
number.
Code:
Output:
Case statements in Linux:
1.) Write a shell script to read an integer and print the month of the year corresponding to that
number Give appropriate message if the number is not between 1 and 12.
Code:
Output:
2.) Write a shell script to find the number of days of the entered month.
Code:
Output:
3.) Write a shell Script to convert lowercase or uppercase as specified by user.
Code:
Output:
4.) Write a menu driven program to perform the following actions
a. Your current Directory
b. Today’s date
c. List of users logged in
Code:
Output:
Conclusion: From the above practical we learn the use of control statements ,switch
statements and looping.