Professional Documents
Culture Documents
Chaitanya Linux
Chaitanya Linux
Program
Chaitanya Sharma
BRANCH : ARTIFILLICAL INTELLIGENCE AND DATA SCIENCE
SEM : 3RD
ROLL NO : 07
SESSION : 2023-2024
1 Linux Shell Program
Index
Sr.no Programs
1. Greatest among three numbers
2. To find a year is leap year or not
3. To input angles of a triangle and find out whether it is valid triangle or not
4. To check whether a character is alphabet, digit or special character
5. To calculate profit or loss
6. Write a shell script to print all even and odd number from 1 to 10
7. Write a shell script to print table of a given number
8. Write a shell script to calculate factorial of a given number.
9. Write a shell script to print sum of all even numbers from 1 to 10.
10. Write a shell script to print sum of digit of any number
11. Write a shell script to make a basic calculator which performs addition, subtraction, Multiplication,
Division
12. Write a shell script to print days of a week
13. Write a shell script to print starting 4 months having 31 days
14. Write a shell script to find a number is Armstrong or not
15. Write a shell script to find a number is palindrome or not
16. Write a shell script to print Fibonacci series
17. Write a shell script to find prime number
18. Write a shell script to convert binary to decimal and decimal to binary
19. Write a Shell script to read and print elements of array
20. Write a Shell script to find sum of all array elements
21. Write a Shell script to find reverse of an array.
22. Write a Shell script to search an element in an array
23. Write a shell script to print different shapes- Diamond
24. Write a shell script to print different : Triangle
25. Write a shell script to print different shapes- Square
26. Write a shell script to print different shapes- Rectangle
27. Write a shell script to print different shapes- Hollow Square
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
2 Linux Shell Program
#!/bin/bash
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
3 Linux Shell Program
else
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
4 Linux Shell Program
if [ $((angle1+angle2+angle3)) -eq 180 ] && [ $angle1 -gt 0 ] && [ $angle2 -gt 0 ] && [ $angle3 -
gt 0 ]; then
echo the entered angle from a valid triangle
else
echo the entered angle are not from valid triangle
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
5 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
6 Linux Shell Program
else
echo there no losses and profit
fi
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
7 Linux Shell Program
Write a shell script to print all even and odd number from 1 to 10.
Syntax:
#!/bin/bash
n=1
j=1
echo Odd number are
while [ $j -le 10 ]
do
if [ $(( j % 2 )) -ne 0 ]; then
echo $j
fi
j=$((j+1))
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
8 Linux Shell Program
n=1
un l [ $n -gt 10 ]
do
echo $num x $n = $((num*n))
n=$((n+1))
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
9 Linux Shell Program
fac=1
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
10 Linux Shell Program
n=1
sum=0
until [ $n -gt 10 ]
do
if [ $((n%2)) -eq 0 ]; then
sum=$((sum+n))
fi
n=$((n+1))
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
11 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
12 Linux Shell Program
Syntax:
#!/bin/bash
read choose
case $choose in
1)
echo The addi on of two number is $((num1+num2))
;;
2)
echo The subtrac on of two number is $((num1-num2))
;;
3)
echo The mul plica on of two number is $((num1*num2))
;;
4)
if [ $num2 -ne 0 ]; then
echo The division is $((num1/num2))
else
echo Error divison by zero
fi
;;
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
13 Linux Shell Program
*)
echo Invalid choosen
;;
esac
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
14 Linux Shell Program
#!/bin/bash
read -p 'Enter a day (1-7) to get the corresponding day of week' day
case $day in
1) echo Sunday;;
2) echo Monday;;
3) echo Tuesday;;
4) echo Wednesday;;
5) echo Thursday;;
6) echo Friday;;
7) echo Saturday;;
*) echo Invalid input;;
esac
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
15 Linux Shell Program
months=( 'January' 'February' 'March' 'April' 'May' 'June' 'July' 'August' 'September' 'October'
'November' 'December' )
counter=1
for (( i=0 ; i<12 ; i++ ));
do
case ${months[i]} in
'January' | 'March' | 'May' | 'July' | 'August' | 'October' | 'December' )
echo ${months[i]}
counter=$((counter+1))
;;
*)
#statment
;;
esac
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
16 Linux Shell Program
Syntax:
#!/bin/bash
Armstrong(){
num=$1
sum=0
temp=$num
temp1=$num
count=0
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
17 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
18 Linux Shell Program
#!/bin/bash
func on palindrone() {
num=$1
sum=0
temp=$num
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
19 Linux Shell Program
Fibonacci(){
limit=$1
a=0
b=1
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
20 Linux Shell Program
isPrime(){
num=$1
count=0
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
21 Linux Shell Program
binarytodecimal(){
binary=$1
base=1
decimal=0
decimaltobinary(){
decimal=$1
binary=0
temp=$binary
binary=0
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
22 Linux Shell Program
temp=$((temp / 10 ))
done
read choose
case $choose in
1)
echo Enter a binary digit
read input
binarytodecimal $input;;
2)
echo Enter a decimal digit
read input
decimaltobinary $input;;
*)
echo Invalid Choose;;
esac
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
23 Linux Shell Program
Syntax:
#!/bin/bash
echo Enter the number of element in array
read num
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
24 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
25 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
26 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
27 Linux Shell Program
echo
done
echo
done
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
28 Linux Shell Program
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
29 Linux Shell Program
echo
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
30 Linux Shell Program
echo
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
31 Linux Shell Program
echo
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh
32 Linux Shell Program
echo
done
Output:
Submi ed By:- Chaitanya Sharma(3rd Sem) Submi ed to:- Mr. Ganesh Singh