os lab 01 - Copy
os lab 01 - Copy
Source code: -
#Date : 10/11/2024
#File : swap.sh
#Title : swapping two numbers
#Description :
read num1
read num2
temp=$num
num1=$num2
num2=$temp
Output: -
#Description:
read number
else
fi
Output: -
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:-
#Description:
read principal
read rate
read time
simple_interest=$(( (principal
*rate * time) / 100 ))
#Description:
read num1
read num2
else
fi
Output: -
Source code: -
#Date : 10/11/2024
#File : largest.sh
#Title : swapping two numbers
#Description :
read num1
read num2
read num3
then
then
else
fi
Output: -
#Description:
while true
do
read num
fact=1
then
do
num=$((num-1))
done
break
then
break
then
else
fi
done
Output: -
Source code: -
#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:-
Source code: -
#Date : 10/11/2024
#File : sum.sh
#Title : T the sum of the first ‘N’ numbers.
#Description :
read N
sum=0
do
sum=$((sum + i))
done
#Description:
while true
do
read num
fact=1
then
do
num=$((num-1))
done
break
then
break
then
else
fi
done
Output: -
Source code: -
#Date : 10/11/2024
#File : Triangle.sh
num=1
echo "Enter the number of rows for Floyd's Triangle:"
read rows
do
do
((num++))
done
echo
done
Output: -
#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: -
#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: -
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
#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: -