[go: up one dir, main page]

100% found this document useful (1 vote)
27 views22 pages

os lab 01 - Copy

Uploaded by

bleu6er
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
27 views22 pages

os lab 01 - Copy

Uploaded by

bleu6er
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Title: - Write a Shell program for swapping two numbers

Source code: -

#Author : Rohit Maji

#Date : 10/11/2024

#File : swap.sh
#Title : swapping two numbers

#Description :

echo "Enter the first number:"

read num1

echo "Enter the second number:"

read num2

temp=$num

num1=$num2

num2=$temp

Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a shell script program to Find Whether the given Number is Even or Odd.
Source code: -

#Author : Rohit Maji


#Date : 10/11/2024
#File : oddeven.sh

#Title : The given Number is Even or Odd

#Description:

echo "Enter a number:"

read number

if [ $((number % 2)) -eq 0 ]; then

echo "$number is Even"

else

echo "$number is Odd"

fi

Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a shell Program to Find Whether the given Number is Positive, Negative or Zero.

Source code: -

#Author

#Date
#File : positivenegativezero.sh

#Title : Find
Whether the iven
number is Positive,
egative or Zero.

#Description:
echo "Enter a number:"
read number
if [ $number -gt 0 ]; then
echo "$number is Positive"
elif [ $number -lt 0 ]; then
echo "$number is Negative"
else
echo "$number is Zero"
fi

Output:-

Course Outcome Programme Outcome


PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11
Title: - Write a shell Program to find Simple Interest.
Source code: -

#Author : Rohit Maji


#Date : 31/08/2024
#File : sipleinterest.sh
#Title : find Simple Interest.

#Description:

echo "Enter the principal


amount(P):"

read principal

echo "Enter the rate of interest


per annum (R):"

read rate

echo "Enter the time period in years (T):"

read time

simple_interest=$(( (principal
*rate * time) / 100 ))

echo "The Simple Interest is:


$simple_interest"
Output: -

Title: - Write a shell Program to Find the Largest of Two Numbers.


Source code: -

#Author : Rohit Maji


#Date : 31/08/2024
#File : largest.sh
#Title : f ind the Largest of Two Numbers.

#Description:

echo "Enter the first number:"

read num1

echo "Enter the second


number:"

read num2

if [ $num1 -gt $num2 ]; then

echo "$num1 is the largest


number."

elif [ $num1 -lt $num2 ]; then

echo "$num2 is the largest


number."

else

echo "Both numbers are


equal."

fi
Output: -

Title: - Write a shell Program to Find the Largest of Three Numbers.

Source code: -

#Author : Rohit Maji

#Date : 10/11/2024

#File : largest.sh
#Title : swapping two numbers

#Description :

echo "Enter the first number:"

read num1

echo "Enter the second number:"

read num2

echo "Enter the third number:"

read num3

# Compare the three numbers

if [ $num1 -gt $num2 ] && [ $num1 -gt


$num3 ];

then

echo "$num1 is the largest number."

elif [ $num2 -gt $num1 ] && [ $num2 -gt


$num3 ];

then

echo "$num2 is the largest number."

else

echo "$num3 is the largest number."

fi
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a shell Program to Find the Factorial for a given range from 0 to 20.
Source code: -

#Author : Rohit Maji


#Date : 10/11/2024
#File : Factorial.sh

#Title : Find the Factorial for a given range from 0 to


20.

#Description:

while true

do

echo "Enter the number between 1 to 20: "

read num

fact=1

if [ $num -ge 1 -a $num -le 20 ]

then

while [ $num -ge 1 ]

do

fact=`expr $fact \* $num`

num=$((num-1))

done

echo "Factorial of a given number is: $fact"

break

elif [ $num -eq 0 ]

then

echo "Factorial of a given number is: 1"

break

elif [ $num -lt 0 ]

then

echo "Error!! negetive number\n"

else

echo "Large number!!\n"

fi

done
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a Shell Program to Check whether a given Year is a Leap Year or Not.

Source code: -

#Author : Rohit Maji


#Date : 10/11/2024
#File : leapyear.sh

#Title : C heck whether a


given Year is a Leap Year or Not

#Description:
echo "Enter a year:"
read year
if [ $((year % 400)) -eq 0 ]; then
echo "$year is a Leap Year."
elif [ $((year % 100)) -eq 0 ]; then
echo "$year is not a Leap Year."
elif [ $((year % 4)) -eq 0 ]; then
echo "$year is a Leap Year."
else
echo "$year is not a Leap Year."
fi

Output:-

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a shell Program to print the sum of the first ‘N’ numbers.

Source code: -

#Author : Rohit Maji

#Date : 10/11/2024

#File : sum.sh
#Title : T the sum of the first ‘N’ numbers.

#Description :

echo "Enter a number N: "

read N

sum=0

for ((i=1; i<=N; i++))

do

sum=$((sum + i))

done

echo "The sum of the first $N numbers is:


$sum"
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a shell Program to Find the Factorial for a given range from 0 to 20.
Source code: -

#Author : Rohit Maji


#Date : 10/11/2024
#File : Factorial.sh

#Title : Find the Factorial for a given range from 0 to


20.

#Description:

while true

do

echo "Enter the number between 1 to 20: "

read num

fact=1

if [ $num -ge 1 -a $num -le 20 ]

then

while [ $num -ge 1 ]

do

fact=`expr $fact \* $num`

num=$((num-1))

done

echo "Factorial of a given number is: $fact"

break

elif [ $num -eq 0 ]

then

echo "Factorial of a given number is: 1"

break

elif [ $num -lt 0 ]

then

echo "Error!! negetive number\n"

else

echo "Large number!!\n"

fi

done
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a Shell Program to Print the Floyd’s Triangle.

Source code: -

#Author : Rohit Maji

#Date : 10/11/2024

#File : Triangle.sh

#Title : Floyd's Triangle


#Description :

num=1
echo "Enter the number of rows for Floyd's Triangle:"

read rows

for (( i=1; i<=rows; i++ ))

do

for (( j=1; j<=i; j++ ))

do

echo -n "$num "

((num++))

done

echo

done
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a Shell Program to Find the GCD and LCM of Two Numbers
Source code: -

#Author : Rohit Maji


#Date : 10/11/2024
#File : g.sh
#Title : Find the GCD and LCM of Two Numbers.

#Description:
gcd() {
local a=$1
local b=$2
while [ $b -ne 0 ]; do
local temp=$b
b=$((a % b))
a=$temp
done
echo $a
}
lcm() {
local a=$1
local b=$2
local gcd_value=$(gcd $a $b)
local lcm_value=$(( (a * b) /
gcd_value ))
echo $lcm_value
}
echo "Enter the first number: "
read num1
echo "Enter the second number: "
read num2
if [ $num1 -le 0 ] || [ $num2 -le 0 ]; then
echo "Please enter positive integers
only."
exit 1
fi
gcd_result=$(gcd $num1 $num2)
lcm_result=$(lcm $num1 $num2)
echo "The GCD of $num1 and $num2 is:
$gcd_result"
echo "The LCM of $num1 and $num2 is:
$lcm_result"
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11


Title: - Write a Shell Progrm to find any multiplication table for any number.
Source code: -

#Author : Rohit Maji


#Date : 31/08/2024
#File : multiplicationtable.sh
#Title : Find any multiplication table for any number.

#Description :
echo "Enter the table number:"
read n
echo "output"
i=1
while [ $i -le 15 ]
do
echo "$n*$i=$(( n * i ))"
i=$(( i+1 ))
done
Output: -

Course Outcome Programme Outcome

PCCCS592.CO1 PO1, PO2, PO3, PO4, PO5, PO7, PO10, PO11

Title: - Write a shell script program which deletes all line containing the word “Unix” in the file shell
argument to shell script

Source code: -
#Author : Rohit Maji

#Date : 10/11/2024

#File : file.txt delete.sh

#Title : which deletes all line


containing the word “Unix”

#Description :

If [$# -lt 1 ];
then

echo “usage:$0<file1><file2>…”

exit 1

fi
for file in “$@”;do

sed -I’/unix/d’”$file”

sed -I’/UNIX/d’”$file"$file”

done

echo”The line was deleted which contain unix word from define file”
Output: -

You might also like