Thursday, May 1, 2008

Write a menu driven program which has following options:

Write a menu driven program which has following options:

a) contents of /etc/passwd

b) List of users who have currently logged in

c) Present working directory

d) Exit

Make use of a case statement. The menu should be placed approximately in the center of the screen and should be displayed in bold using the tput statement.

# SS17

# Menu driven program

# Usage: SS17

clear

while true

do

clear

tput cup 10 20

echo “1. contents of/etc/passwd”

tput cup 11 20

echo “2. List of users who have logged in”

tput cup 12 20

echo “3. Present working director”

tput cup 13 20

echo “4. Exit”

tput cup 15 20

echo “Your choice?”

read ans

clear

case $ans in

a) cat/etc/passwd;;

b) who;;

c) pwd;;

d) exit;;

esac

echo “n\nPress any key to continue...”

read key >/dev/null

done

3 comments:

Anonymous said...

plz..post the output..as well..

its not working

Anonymous said...

plz post the output as well..

its not working

Unknown said...

Try Below code |-
----------------------------------------------------

choice=0

while [ $choice -lt 4 ]
do
tput clear
echo "1. contents of etc/passwd"
echo "2. list of the users who have logged in"
echo "3. Present working directory"
echo "4. Exit"
echo "Enter your choice "
read choice

if [ $choice -eq 1 ]
then
cat /etc/passwd | more
read a
elif [ $choice -eq 2 ]
then
who | more
read a
elif [ $choice -eq 3 ]
then
pwd
read a
fi
done