# Write a script to create a
menu using case?
$vi menu_case.sh
clear
tput cut 10 25
echo “main menu”
tput cut 11 25
echo “————“
tput cut 12 25
echo “1.Date “
tput cut 13 25
echo “2.All files”
tput cut 13 25
echo “3.All Users”
tput cut 14 25
echo “4.No items found”
read choice
case $choice in
1)echo “Today Date ::” `date`
;;
2)ls -f
;;
3)finger
;;
*)exit
;;
esac
:wq
clear
tput cut 10 25
echo “main menu”
tput cut 11 25
echo “————“
tput cut 12 25
echo “1.Date “
tput cut 13 25
echo “2.All files”
tput cut 13 25
echo “3.All Users”
tput cut 14 25
echo “4.No items found”
read choice
case $choice in
1)echo “Today Date ::” `date`
;;
2)ls -f
;;
3)finger
;;
*)exit
;;
esac
:wq
# Write a script to check the given type of character?
$vi char_type.sh
echo “enter a character”
read char
case $char in
[a-z])echo “lower case”
;;
[A-Z])echo “upper case”
;;
[0-9])echo “Digit”
;;
?)echo “special character”
;;
*)echo “Entered more than one character”
;;
esac
:wq
echo “enter a character”
read char
case $char in
[a-z])echo “lower case”
;;
[A-Z])echo “upper case”
;;
[0-9])echo “Digit”
;;
?)echo “special character”
;;
*)echo “Entered more than one character”
;;
esac
:wq
# Write a script to check the given two file are equal or not?
$vi twofiles_same.sh
echo “enter first file “
read f1
echo “enter second file”
read f2
x =`cmp $f1 $f2`
if [-z $x]
then
echo “both are same”
else
echo “both are not same”
fi
:wq
echo “enter first file “
read f1
echo “enter second file”
read f2
x =`cmp $f1 $f2`
if [-z $x]
then
echo “both are same”
else
echo “both are not same”
fi
:wq
# Write a script open the given file?
$vi open_file.sh
echo “enter file name:”
read fname
if [-e $fname]
then
if [-f $fname]
then
if [-r $fname]
then
cat $fname
else
chmod u+r $fname
cat $fname
else “it is not a regular file”
else
echo “It is not a regualr file”
else
echo “file doesnt exist”
fi
:wq
echo “enter file name:”
read fname
if [-e $fname]
then
if [-f $fname]
then
if [-r $fname]
then
cat $fname
else
chmod u+r $fname
cat $fname
else “it is not a regular file”
else
echo “It is not a regualr file”
else
echo “file doesnt exist”
fi
:wq
# Write a script to check the
given type of file?
$vi type_file.sh
echo “enter file name:”
read fname
if [ -e $fname ]
then
if [ -f $fname ]
then
echo “regular file “
else
echo “directory file “
elif [ -l $fname ]
then
echo ” link file”
elif [ -b $fname -o -c $fname ]
then
echo “Device file”
fi
:wq
echo “enter file name:”
read fname
if [ -e $fname ]
then
if [ -f $fname ]
then
echo “regular file “
else
echo “directory file “
elif [ -l $fname ]
then
echo ” link file”
elif [ -b $fname -o -c $fname ]
then
echo “Device file”
fi
:wq
# Write a script to check the given user is logged in or not?
$vi delete.sh
echo “enter login name:”
read lname
if who | grep $lname > /dev/null
then
echo “user is online”
else
echo “user is offline “
fi
:wq
echo “enter login name:”
read lname
if who | grep $lname > /dev/null
then
echo “user is online”
else
echo “user is offline “
fi
:wq
# Write a script to delete the given file?
$vi delete.sh
echo “enter filename:”
read fname
if rm $fname
then
echo “deleted the file”
else
echo “file is not existed “
fi
:wq
echo “enter filename:”
read fname
if rm $fname
then
echo “deleted the file”
else
echo “file is not existed “
fi
:wq
# Write a script to accept two strings and check the given strings
are equal or not?
$vi two_strings.sh
echo “enter first string:”
read s1
echo “enter second string:”
read s2
if [ "$s1" = "$s2" ]
then
echo “equal”
else
echo “not equal”
fi
:wq
echo “enter first string:”
read s1
echo “enter second string:”
read s2
if [ "$s1" = "$s2" ]
then
echo “equal”
else
echo “not equal”
fi
:wq
# Write a script to check the given number is
even or odd number?
$vi even_odd.sh
echo “enter a number: “
read n
if [ `expr $n % 2` = 0 ]
then
echo “entered number : even number”
else
echo “entered number : odd number “
fi
:wq
echo “enter a number: “
read n
if [ `expr $n % 2` = 0 ]
then
echo “entered number : even number”
else
echo “entered number : odd number “
fi
:wq
#Write a script to check the given number is positive
or negative?
$vi pos_neg.sh
echo “enter a number: “
read n
if [ $n gt 0 ]
then
echo “entered number : positive number”
else
echo “entered number : negative number”
fi
:wq
echo “enter a number: “
read n
if [ $n gt 0 ]
then
echo “entered number : positive number”
else
echo “entered number : negative number”
fi
:wq
No comments:
Post a Comment