0% found this document useful (0 votes)
14 views

ProgramSolution OS

The document contains 20 shell script programs that perform tasks like displaying the date, time and day, calculating mathematical operations, checking even/odd/positive/negative/zero values, finding sum of natural numbers, factorials, sorting files etc. Each program is labeled and contains commands like date, read, echo, if/else, case, while loops, sort etc to implement the given logic.

Uploaded by

rumeshavahora100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

ProgramSolution OS

The document contains 20 shell script programs that perform tasks like displaying the date, time and day, calculating mathematical operations, checking even/odd/positive/negative/zero values, finding sum of natural numbers, factorials, sorting files etc. Each program is labeled and contains commands like date, read, echo, if/else, case, while loops, sort etc to implement the given logic.

Uploaded by

rumeshavahora100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

// Program:-1

date +"Today is %B %d %Y"


date +"Today is %A"
date +"Time is in %r"
// Program:-2
a=40
b=62

sum=$(($a + $b))
echo "Sum of 2 num is : $sum"

// Program:-3

echo "Enter n1:"


read n1
echo "Enter n2:"
read n2

sum=$(($n1+$n2))
minus=$(($n1-$n2))
multiply=$(($n1*$n2))
div=$(($n1/$n2))
echo "Addision = $sum"
echo "Subtraction = $minus"
echo "Multiplication = $multiply"
echo "Division = $div"

// Program:-4

echo "Enter M:"


read m
echo "Enter N:"
read n
if [ $m -gt $n ]
then
echo "$m is Maximum"
else
echo "$n is Maximum"
fi
// Program:-5

echo "Enter Value:"


read v

if [ $(($v % 2)) -eq 0 ]


then
echo "$v is Even"
else
echo "$v is Odd"
fi

// Program:-6

echo "Enter Value:"


read v
if [ $v -gt 0 ]
then
echo "$v is Positive"
elif [ $v -lt 0 ]
then
echo "$v is Negative"
else
echo "$v is Zero"
fi

// Program:-7

echo "Enter Value:"


read v
i=1
sum=0

while [ $i -le $v ]
do
sum=$(($sum+$i))
i=$(($i+1))
done
echo "Sum of n Natural number: $sum"
// Program:-8

echo "Enter Value:"


read v
fact=1
m=1
while [ $m -le $v ]
do
fact=$(($fact*$m))
m=$(($m+1))
done
echo "The Factorial of $v is $fact"

// Program:-9

echo "Enter Number"


read n
m=1
e=0
o=0
while [ $m -le $n ]
do
if [ $(( $m % 2 )) -eq 0 ]
then
echo "$m"
e=$(( $e+$m ))
else
echo "$m"
o=$(( $o+$m ))
fi
m=$(($m+1))
done
echo "Sum of Even numbers = $e"
echo "Sum of Odd numbers = $o"

// Program:-10

echo "Enter Number:"


read a
m=1
p=0
while [ $m -le $a ]
do
if [ $(($a % $m)) -eq 0 ]
then
p=$(($p+1))
fi
m=$(($m+1))
done
if [ $p -eq 2 ]
then
echo "$a is Prime"
else
echo "$a is not Prime"
fi

// Program:-11

echo "Enter code from 1-2:"


read a
case $a in
1) echo "you entered $a"
;;
2) echo "you entered $a"
;;
*) echo "wrong code"
;;
esac

// Program:-12

echo "Enter code from 1-4:"


read a
case $a in
1) echo "you entered $a"
;;
2) echo "you entered $a"
;;
3) echo "you entered $a"
;;
4) echo "you entered $a"
;;
*) echo "wrong code"
;;
esac
// Program:-13

c=1
while [ $c -ne 6 ]
do
echo "1.. Copy source file to destination"
echo "2.. Rename the specified file"
echo "3.. Print the specified file"
echo "4.. Change permission of specified file to (read,write) for all users"
echo "5.. Display size of specified file in number of character (byte)"
echo "6.. Exit"
echo "Enter your Choice from above:"
read c
echo "Enter file name:"
read f

case $c in
1) read -p "Enter destination directory name:" dn
cp $f $dn
;;
2) read -p "Enter new file name::" nf
mv $f $nf
;;
3) cat $f
;;
4) chmod u+rw $f
ls -l $f
;;
5) wc -c $f
;;
6) exit
;;
*) echo "Wrong choice"
;;
esac
done

// Program:-14

c=1
while [ $c -ne 3 ]
do
echo "1.. List of users who have logged in"
echo "2.. Present work directory "
echo "3.. Exit"
echo "Enter choice from above.."
read c
case $c in
1) #who
z=$(who)
echo "$z"
;;
2) #pwd
z=$(pwd)
echo "$z"
;;
3) exit
;;
*) echo "wrong choice"
;;
esac
done

// Program:-15

read -p "choose path to remove the file" z


cd "$z"
read -p "select extension without using '.'" y
rm *."$y"
echo "file with extension $y is removed from $z"

// Program:-16

read -p "Change permission of particular file: " y


chmod u+vw $y
echo "Permission granted for $y"
ls -l $y

// Program:-17

for file in *
do
if [ -f "$file" ]
then
echo "$file"
fi
done

// Program:-18

for z in */
do
if [ -d "$z" ]
then
echo "$z"
fi
done

// Program:-19

c=1
while [ $c -ne 3 ]
do
echo "1.. ls"
echo "2.. who"
echo "3.. pwd "
echo "4.. Exit"
echo "Enter choice from above.."
read c
case $c in
1) #ls
z=$(ls)
echo "$z"
;;
2) #who
z=$(who)
echo "$z"
;;
3) #pwd
z=$(pwd)
echo "$z"
;;
4) exit
;;
*) echo "wrong choice"
;;
esac
done

// Program:-20

c=1
while [ $c -ne 6 ]
do
echo "1.. Sort the file in ascending order"
echo "2.. Sort the file in descending order"
echo "3.. Sort the file by ignoring case"
echo "4.. Sort the file by avoiding duplication(unique record)"
echo "5.. Count number of words"
echo "6.. Exit"
echo "Enter choice from above"
read c
echo "Enter file name: "
read y
case $c in
1) z=$(sort $y)
echo "$z"
;;
2) z=$(sort -r $y)
echo "$z"
;;
3) z=$(sort -f $y)
echo "$z"
;;
4) z=$(sort -u $y)
echo "$z"
;;
5) z=$(wc -w $y)
echo "$z"
;;
6) exit
;;
*) echo "wrong choice"
;;
esac
done
program-20 computer.lst file

"disk drive"
"memory"
"video memory"
"monitor"
"tape drive"
"CD-ROM"
"modem"
"monitor"
"sound laster"

You might also like