0% found this document useful (0 votes)
27 views7 pages

Program

Uploaded by

gurgrewal
Copyright
© Attribution Non-Commercial (BY-NC)
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
0% found this document useful (0 votes)
27 views7 pages

Program

Uploaded by

gurgrewal
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 7

hLLp//wwwsynLaxexamplecom/Code/menudrlvenshellscrlpLcopyflle1618aspx

Write a sheII script to find the Iargest among the 3 given numbers in
Unix / Linux
echo Enter 3 numbers with spaces in between
read a b c
l=$a
if $b -gt $l ,
then
l=$b
fi
if $c -gt $l ,
then
l=$c
fi
echo Lagest of $a $b $c is $l
ode for SheII script to change extension of an existing fiIe in Unix /
Linux
clear
echo "Enter first file name: "
read f1
if -f $f1 ,
then
echo "Enter new extention: "
read e

cp $,f1, $,f1,.$e

# i=basename $f1
# b= $i txt

# for file in .txt
# i=`basename file txt`
# mv $file $i doc

echo $f1"."$e" file is created"else
echo "File not Exist "
fi

ode for Write a menu driven sheII script for opy a fiIe, Remove a fiIe,
Move a fiIe in Unix / Linux

clear
echo "Menu "
echo "1. CJpy a File "
echo "2. Remove a file "
echo "3. Move a file"
echo "4. Quit"
echo "Enter ur Choice \c"
read Choice
case"$Choice"in
1) echo "Enter File name to copy \c"
read f1
echo "Enter FIle name \c "
read f2
if -f $f1 ,
then
cp $f1 $f2
else
echo "$f1 does not exist"
fi
;;
2) echo "Enter the File to be removed "
read r1
if -f $r1 ,
then
rm -i $r1
else
echo "$r1 file does not exist "
fi
;;
3)
echo "Enter File name to move \c"
read f1
echo "Enter destination \c "
read f2
if -f $f1 ,
then
if -d $f2 ,
then
mv $f1 $f2
fi
else
echo "$f1 does not exist"
fi
;;
4)
echo "Exit......."
exit;;
esac

--------------------------------------------------------------------------------

JUTPUT:

$ sh38
Menu
1. CJpy a File
2. Remove a file
3. Move a file
4. Quit
Enter ur Choice 1
Enter File name to copy r1
Enter FIle name r2
$ sh38
Menu
1. CJpy a File
2. Remove a file
3. Move a file
4. Quit
Enter ur Choice 3
Enter File name to move r1
Enter destination r3
$ sh38
Menu
1. CJpy a File
2. Remove a file
3. Move a file
4. Quit
Enter ur Choice 2
Enter the File to be removed r1
remove r1. y

ode for SheII Script to make a menu driven caIcuIator using case in
Unix / Linux
clear
sum=0
i="y"

echo " Enter one no."
read n1
echo "Enter second no."
read n2
while $i = "y" ,
do
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
echo "Enter your choice"
read ch
case $ch in
1)sum=`expr $n1 + $n2`
echo "Sum ="$sum;;
2)sum=`expr $n1 - $n2`
echo "Sub = "$sum;;
3)sum=`expr $n1 \ $n2`
echo "Mul = "$sum;;
4)sum=`expr $n1 / $n2`
echo "Div = "$sum;;
)echo "Invalid choice";;
esac
echo "Do u want to continue ."
read i
if $i != "y" ,
then
exit
fi
done










JUTPUT

04mca58@LINTEL 04mca58,$ sh calculator.sh
Enter any no.
121
Enter one no.
21
Enter second no.
58
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
1
Sum =79
Do u want to continue .
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
2
Sub = -37
Do u want to continue .
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
3
Mul = 1218
Do u want to continue .
y
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter your choice
4
Div = 0
Do u want to continue .
n
JrlLeamenudrlvenprogramLodlsplaymessageusernameLermlnalnameloglndaLeandLlmeln
Dnlx
Write a menu driven program to dispIay message, user name, terminaI
name, Iogin date and time in Unix / Linux
choice=0

while $choice -ne 4 ,
do
tput clear

echo "1. Today date and time"
echo "2. Total login user"
echo "3. My detail"
echo "4. Exit"
echo "Enter your choice"
read choice

if $choice -eq 1 ,
then
echo "Today is `date +%B` `date | cut -f 3 -d ""`, `date | cut -f 6 -d ""`"
echo " and current time is `date | cut -f 4 -d ""`"

elif $choice -eq 2 ,
then
echo "As of now `who | wc -l` user are login to the system"

elif $choice -eq 3 ,
then
echo "My details :-------"
echo "user name : `who i am | cut -f 1 -d ""`"
echo "Terminal name: `who i am | cut -f 4 -d ""`"
echo "Login date : `who i am | cut -f 12-13, -d ""`"
echo "Login time : `who i am | cut -f 14 -d ""`"
fi
echo "Are you continue (1 for yes/0 for n)"
read temp

if $temp -eq 0 ,
then
choice=4
fi
done

ode for Write a sheII script to find sum of digits of a number in Unix /
Linux
echo -n "Input no : "
read no

length=`expr length $no`

while $length -ne 0 ,
do
b=`expr substr $no $length 1`
ans=`expr $ans + $b`
length=`expr $length - 1`
done
echo "Sum of Digit is : $ans"

Write a sheII script to reverse a number suppIied by a user in Unix /


Linux
if $# -eq 1 ,
then
if $1 -gt 0 ,
then
num=$1
sumi=0
while $num -ne 0 ,
do
lnum=`expr $num % 10`
sumi=`expr $sumi 10 + $lnum`
num=`expr $num \/ 10`
done
echo "Reverse of digits is $sumi of $1"else
echo " Number is less than 0"
fi
else
echo "Insert only one parameter "
fi

--------------------------------------------------------------------------------

output:

$ sh1 23456
Reverse of digits is 65432 of 23456

Write a sheII program to exchange the vaIues of two variabIes


ode for SheII script to measure size of a fiIe in Unix / Linux
clear
echo "Enter any file name: "
read filenm
if -e $filenm ,
then
echo $filenm" File exist"if -s $filenm ,
then
echo $filenm" File has size 0"else
rm $filenm
echo $filenm" File is Deleted which has size = 0"
fi
else
echo "File not exist"
fi
ode for Write a sheII script, which wiII receive any number of fiIenames
as arguments .The sheII script shouId check whether such fiIes aIready
exist. in Unix / Linux
for i in $
doif -f $i ,
then
echo "File $i is already exist."elseif -d mydir ,
then
cnt=0
cd mydir
for j in `ls`
doif -f $j ,
then
cnt=`expr $cnt + 1`
fi
done
echo "Mydir already exist...contains $cnt files"else
mkdir mydir
cd mydir
$i
fi
fi
done
Write a sheII script to reverse the contents of a fiIe in Unix / Linux
if $# -eq 1 ,
then
if -f $1 ,
then
a=`rev $1`
echo "Reverse of $1"
cat $1
echo " is- $a"else
echo "File does not exist '
fi

else
echo "Please enter file name or path"
fi

--------------------------------------------------------------------------------

JUTPUT:

$ sh35 wordfile1
Reverse of
apple
mango
banana
chicko
is- elppa
ognam
ananab
okcihc

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy