Bash menu
- mo_mughrabi
- Student


- Joined: Nov 07, 2006
- Posts: 73
- Status: Offline
Hello,
I been working on a shell menu using Solaris (Unix) and when i moved the code to redhat linux it's not working properly. Am not sure what should i update within the code,, please help
#!/bin/sh
#########################
# FILE MENU #
#########################
fitxt() {
clear
echo `date`
echo
echo " Please make select"
echo
echo " 1. Display the contents of a file"
echo " 2. Remove a file"
echo " 3. Copy a file"
echo " 4. List a file"
echo " 5. Size of a file"
echo " 6. Return to main menu"
echo
echo " ENTER YOUR OPTION:"
}
filoop() {
while true
do
fitxt
read answer
case $answer in
1)
DisplayFileContent
;;
2)
RemvFil
;;
3)
CopFil
;;
4)
ListFil
;;
5)
SizFill
;;
6)
helploop
;;
*)
filoop
;;
esac
done
}
DisplayFileContent() {
clear
echo "Please enter the full path to file and file name"
echo
read filename
clear
if [ -f $filename ]
then
cat $filename|more
else
echo "WRONG FILE NAME"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
RemvFil() {
clear
echo "Please enter the full path to file you want to delete"
echo
read filename
clear
if [ -f $filename ]
then
echo "Are you sure you want to delete $filename? Type (yes/no)"
read answer
if [ $answer = "yes" ]
then
rm -f $filename
echo "FILE WAS REMOVED SUCCESSFULLY"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
CopFil() {
clear
echo "Please enter full path name which you wish to copy? "
echo
read filename
if [ -f $filename ]
then
echo "Please enter directory path where you wish to copy the file?"
read copyto
if [ -d $copyto ]
then
cp $filename $copyto
echo "FILE WAS COPIED SUCCESSFULLY"
else
echo "WRONG PARAMETER: Only directory path are allowed"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
ListFil() {
clear
echo "Please enter path to directory to list down files"
echo
read dirname
clear
if [ -d $dirname ]
then
ls -ltr $dirname|more
else
echo "WRONG PATH"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
SizFill() {
clear
echo "Please enter file name to get file size"
echo
read filname
clear
if [ -f $filname ]
then
echo "$filname = `ls -ltr $filname| awk {'print $5'}`"
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
##############################
# End FILE MENU #
##############################
#################################
# Text processing menu #
#################################
proctxt() {
clear
echo `date`
echo
echo " Please make your selection"
echo
echo " 1. Search a file for a pattern"
echo " 2. Count lines, words, and characters in specified files"
echo " 3. Display line differences between two files"
echo " 4. Return to Main Menu"
echo
echo " Please enter:"
}
procloop() {
while true
do
proctxt
read answer
case $answer in
1)
SearchFile
;;
2)
CountLineWordsChars
;;
3)
DisLineDiff
;;
4)
helploop
;;
*)
procloop
;;
esac
done
}
SearchFile() {
clear
echo "Please enter file name you wish to search"
echo
read filname
echo
if [ -f $filname ]
then
echo "Please enter key word to search for?"
read keyword
egrep $keyword $filname|more
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
CountLineWordsChars() {
clear
echo "Please enter file name you wish to count words, char and lines"
echo
read filname
echo
if [ -f $filname ]
then
echo "Number of characters in $filname: `cat $filname|wc -m`"
echo
echo "Number of lines in $filname: `cat $filname|wc -l`"
echo
echo "Number of words in $filename: `cat $filname|wc -w`"
echo
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
DisLineDiff() {
clear
echo "Please enter first file name u wish to compare"
echo
read filname
echo
if [ -f $filname ]
then
echo "Please enter second file you want to compare?"
read filname2
if [ -f $filname2 ]
then
diff $filname $filname2
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
#################################
# End Text processing menu #
#################################
#################################
# status menu #
#################################
statxt() {
clear
echo `date`
echo
echo
echo " Please make your selection"
echo
echo " 1. Display the current date and time"
echo " 2. Current disk usage"
echo " 3. Display process status information"
echo
echo " 4. Return to main menu"
echo
echo " ENTER YOUR OPTION:"
}
statloop() {
while true
do
statxt
read answer
case $answer in
1)
DisDateTime
;;
2)
DiskSpace
;;
3)
DisplayProcStatus
;;
4)
helploop
;;
*)
statloop
;;
esac
done
}
DisDateTime() {
clear
echo
echo " DATE: `date '+%b %d %Y'`"
echo
echo " TIME: `date '+%H:%M '`"
echo
echo "PRES ANY KEY TO CONTINUE......"
echo
read answer
statloop
}
DiskSpace() {
clear
echo
echo " DISK SPACE..."
echo
df -k
echo
echo
echo "PRES ANY KEY TO RETURN BACK...."
read answer
loopstat
}
DisplayProcStatus() {
clear
echo
echo " List of running processes...."
echo
ps -ef|more
echo
read answer
loopstat
}
########################
# HELP MENU #
########################
helptxt() {
clear
echo `date`
echo
echo
echo " Please make select"
echo
echo " 1. Help (Main Menu)"
echo " 2. File Management Commands (Sub-Menu)"
echo " 3. Text Processing Commands (Sub-Menu)"
echo " 4. System Status Commands (Sub-Menu)"
echo
echo " 5. Exit"
echo
echo " ENTER YOUR OPTION:"
}
helploop() {
while true
do
helptxt
read answer
case $answer in
1)
helploop
;;
2)
filoop
;;
3)
procloop
;;
4)
statloop
;;
5)
exit
;;
*)
helploop
;;
esac
done
}
case "$1" in
help)
helploop
;;
file)
filoop
;;
text)
procloop
;;
status)
statloop
;;
*)
helploop
;;
esac
I been working on a shell menu using Solaris (Unix) and when i moved the code to redhat linux it's not working properly. Am not sure what should i update within the code,, please help
Code: [ Select ]
#!/bin/sh
#########################
# FILE MENU #
#########################
fitxt() {
clear
echo `date`
echo
echo " Please make select"
echo
echo " 1. Display the contents of a file"
echo " 2. Remove a file"
echo " 3. Copy a file"
echo " 4. List a file"
echo " 5. Size of a file"
echo " 6. Return to main menu"
echo
echo " ENTER YOUR OPTION:"
}
filoop() {
while true
do
fitxt
read answer
case $answer in
1)
DisplayFileContent
;;
2)
RemvFil
;;
3)
CopFil
;;
4)
ListFil
;;
5)
SizFill
;;
6)
helploop
;;
*)
filoop
;;
esac
done
}
DisplayFileContent() {
clear
echo "Please enter the full path to file and file name"
echo
read filename
clear
if [ -f $filename ]
then
cat $filename|more
else
echo "WRONG FILE NAME"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
RemvFil() {
clear
echo "Please enter the full path to file you want to delete"
echo
read filename
clear
if [ -f $filename ]
then
echo "Are you sure you want to delete $filename? Type (yes/no)"
read answer
if [ $answer = "yes" ]
then
rm -f $filename
echo "FILE WAS REMOVED SUCCESSFULLY"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
CopFil() {
clear
echo "Please enter full path name which you wish to copy? "
echo
read filename
if [ -f $filename ]
then
echo "Please enter directory path where you wish to copy the file?"
read copyto
if [ -d $copyto ]
then
cp $filename $copyto
echo "FILE WAS COPIED SUCCESSFULLY"
else
echo "WRONG PARAMETER: Only directory path are allowed"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
ListFil() {
clear
echo "Please enter path to directory to list down files"
echo
read dirname
clear
if [ -d $dirname ]
then
ls -ltr $dirname|more
else
echo "WRONG PATH"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
SizFill() {
clear
echo "Please enter file name to get file size"
echo
read filname
clear
if [ -f $filname ]
then
echo "$filname = `ls -ltr $filname| awk {'print $5'}`"
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
##############################
# End FILE MENU #
##############################
#################################
# Text processing menu #
#################################
proctxt() {
clear
echo `date`
echo
echo " Please make your selection"
echo
echo " 1. Search a file for a pattern"
echo " 2. Count lines, words, and characters in specified files"
echo " 3. Display line differences between two files"
echo " 4. Return to Main Menu"
echo
echo " Please enter:"
}
procloop() {
while true
do
proctxt
read answer
case $answer in
1)
SearchFile
;;
2)
CountLineWordsChars
;;
3)
DisLineDiff
;;
4)
helploop
;;
*)
procloop
;;
esac
done
}
SearchFile() {
clear
echo "Please enter file name you wish to search"
echo
read filname
echo
if [ -f $filname ]
then
echo "Please enter key word to search for?"
read keyword
egrep $keyword $filname|more
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
CountLineWordsChars() {
clear
echo "Please enter file name you wish to count words, char and lines"
echo
read filname
echo
if [ -f $filname ]
then
echo "Number of characters in $filname: `cat $filname|wc -m`"
echo
echo "Number of lines in $filname: `cat $filname|wc -l`"
echo
echo "Number of words in $filename: `cat $filname|wc -w`"
echo
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
DisLineDiff() {
clear
echo "Please enter first file name u wish to compare"
echo
read filname
echo
if [ -f $filname ]
then
echo "Please enter second file you want to compare?"
read filname2
if [ -f $filname2 ]
then
diff $filname $filname2
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
else
echo "WRONG PARAMETER: Only allowed to enter file name including full path"
fi
echo
echo "PRESS ENTER TO GO BACK...."
read GOBACK
loopfil
}
#################################
# End Text processing menu #
#################################
#################################
# status menu #
#################################
statxt() {
clear
echo `date`
echo
echo
echo " Please make your selection"
echo
echo " 1. Display the current date and time"
echo " 2. Current disk usage"
echo " 3. Display process status information"
echo
echo " 4. Return to main menu"
echo
echo " ENTER YOUR OPTION:"
}
statloop() {
while true
do
statxt
read answer
case $answer in
1)
DisDateTime
;;
2)
DiskSpace
;;
3)
DisplayProcStatus
;;
4)
helploop
;;
*)
statloop
;;
esac
done
}
DisDateTime() {
clear
echo
echo " DATE: `date '+%b %d %Y'`"
echo
echo " TIME: `date '+%H:%M '`"
echo
echo "PRES ANY KEY TO CONTINUE......"
echo
read answer
statloop
}
DiskSpace() {
clear
echo
echo " DISK SPACE..."
echo
df -k
echo
echo
echo "PRES ANY KEY TO RETURN BACK...."
read answer
loopstat
}
DisplayProcStatus() {
clear
echo
echo " List of running processes...."
echo
ps -ef|more
echo
read answer
loopstat
}
########################
# HELP MENU #
########################
helptxt() {
clear
echo `date`
echo
echo
echo " Please make select"
echo
echo " 1. Help (Main Menu)"
echo " 2. File Management Commands (Sub-Menu)"
echo " 3. Text Processing Commands (Sub-Menu)"
echo " 4. System Status Commands (Sub-Menu)"
echo
echo " 5. Exit"
echo
echo " ENTER YOUR OPTION:"
}
helploop() {
while true
do
helptxt
read answer
case $answer in
1)
helploop
;;
2)
filoop
;;
3)
procloop
;;
4)
statloop
;;
5)
exit
;;
*)
helploop
;;
esac
done
}
case "$1" in
help)
helploop
;;
file)
filoop
;;
text)
procloop
;;
status)
statloop
;;
*)
helploop
;;
esac
- #!/bin/sh
- #########################
- # FILE MENU #
- #########################
- fitxt() {
- clear
- echo `date`
- echo
- echo " Please make select"
- echo
- echo " 1. Display the contents of a file"
- echo " 2. Remove a file"
- echo " 3. Copy a file"
- echo " 4. List a file"
- echo " 5. Size of a file"
- echo " 6. Return to main menu"
- echo
- echo " ENTER YOUR OPTION:"
- }
- filoop() {
- while true
- do
- fitxt
- read answer
- case $answer in
- 1)
- DisplayFileContent
- ;;
- 2)
- RemvFil
- ;;
- 3)
- CopFil
- ;;
- 4)
- ListFil
- ;;
- 5)
- SizFill
- ;;
- 6)
- helploop
- ;;
- *)
- filoop
- ;;
- esac
- done
- }
- DisplayFileContent() {
- clear
- echo "Please enter the full path to file and file name"
- echo
- read filename
- clear
- if [ -f $filename ]
- then
- cat $filename|more
- else
- echo "WRONG FILE NAME"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- RemvFil() {
- clear
- echo "Please enter the full path to file you want to delete"
- echo
- read filename
- clear
- if [ -f $filename ]
- then
- echo "Are you sure you want to delete $filename? Type (yes/no)"
- read answer
- if [ $answer = "yes" ]
- then
- rm -f $filename
- echo "FILE WAS REMOVED SUCCESSFULLY"
- fi
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- CopFil() {
- clear
- echo "Please enter full path name which you wish to copy? "
- echo
- read filename
- if [ -f $filename ]
- then
- echo "Please enter directory path where you wish to copy the file?"
- read copyto
- if [ -d $copyto ]
- then
- cp $filename $copyto
- echo "FILE WAS COPIED SUCCESSFULLY"
- else
- echo "WRONG PARAMETER: Only directory path are allowed"
- fi
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- ListFil() {
- clear
- echo "Please enter path to directory to list down files"
- echo
- read dirname
- clear
- if [ -d $dirname ]
- then
- ls -ltr $dirname|more
- else
- echo "WRONG PATH"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- SizFill() {
- clear
- echo "Please enter file name to get file size"
- echo
- read filname
- clear
- if [ -f $filname ]
- then
- echo "$filname = `ls -ltr $filname| awk {'print $5'}`"
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- ##############################
- # End FILE MENU #
- ##############################
- #################################
- # Text processing menu #
- #################################
- proctxt() {
- clear
- echo `date`
- echo
- echo " Please make your selection"
- echo
- echo " 1. Search a file for a pattern"
- echo " 2. Count lines, words, and characters in specified files"
- echo " 3. Display line differences between two files"
- echo " 4. Return to Main Menu"
- echo
- echo " Please enter:"
- }
- procloop() {
- while true
- do
- proctxt
- read answer
- case $answer in
- 1)
- SearchFile
- ;;
- 2)
- CountLineWordsChars
- ;;
- 3)
- DisLineDiff
- ;;
- 4)
- helploop
- ;;
- *)
- procloop
- ;;
- esac
- done
- }
- SearchFile() {
- clear
- echo "Please enter file name you wish to search"
- echo
- read filname
- echo
- if [ -f $filname ]
- then
- echo "Please enter key word to search for?"
- read keyword
- egrep $keyword $filname|more
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- CountLineWordsChars() {
- clear
- echo "Please enter file name you wish to count words, char and lines"
- echo
- read filname
- echo
- if [ -f $filname ]
- then
- echo "Number of characters in $filname: `cat $filname|wc -m`"
- echo
- echo "Number of lines in $filname: `cat $filname|wc -l`"
- echo
- echo "Number of words in $filename: `cat $filname|wc -w`"
- echo
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- DisLineDiff() {
- clear
- echo "Please enter first file name u wish to compare"
- echo
- read filname
- echo
- if [ -f $filname ]
- then
- echo "Please enter second file you want to compare?"
- read filname2
- if [ -f $filname2 ]
- then
- diff $filname $filname2
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- else
- echo "WRONG PARAMETER: Only allowed to enter file name including full path"
- fi
- echo
- echo "PRESS ENTER TO GO BACK...."
- read GOBACK
- loopfil
- }
- #################################
- # End Text processing menu #
- #################################
- #################################
- # status menu #
- #################################
- statxt() {
- clear
- echo `date`
- echo
- echo
- echo " Please make your selection"
- echo
- echo " 1. Display the current date and time"
- echo " 2. Current disk usage"
- echo " 3. Display process status information"
- echo
- echo " 4. Return to main menu"
- echo
- echo " ENTER YOUR OPTION:"
- }
- statloop() {
- while true
- do
- statxt
- read answer
- case $answer in
- 1)
- DisDateTime
- ;;
- 2)
- DiskSpace
- ;;
- 3)
- DisplayProcStatus
- ;;
- 4)
- helploop
- ;;
- *)
- statloop
- ;;
- esac
- done
- }
- DisDateTime() {
- clear
- echo
- echo " DATE: `date '+%b %d %Y'`"
- echo
- echo " TIME: `date '+%H:%M '`"
- echo
- echo "PRES ANY KEY TO CONTINUE......"
- echo
- read answer
- statloop
- }
- DiskSpace() {
- clear
- echo
- echo " DISK SPACE..."
- echo
- df -k
- echo
- echo
- echo "PRES ANY KEY TO RETURN BACK...."
- read answer
- loopstat
- }
- DisplayProcStatus() {
- clear
- echo
- echo " List of running processes...."
- echo
- ps -ef|more
- echo
- read answer
- loopstat
- }
- ########################
- # HELP MENU #
- ########################
- helptxt() {
- clear
- echo `date`
- echo
- echo
- echo " Please make select"
- echo
- echo " 1. Help (Main Menu)"
- echo " 2. File Management Commands (Sub-Menu)"
- echo " 3. Text Processing Commands (Sub-Menu)"
- echo " 4. System Status Commands (Sub-Menu)"
- echo
- echo " 5. Exit"
- echo
- echo " ENTER YOUR OPTION:"
- }
- helploop() {
- while true
- do
- helptxt
- read answer
- case $answer in
- 1)
- helploop
- ;;
- 2)
- filoop
- ;;
- 3)
- procloop
- ;;
- 4)
- statloop
- ;;
- 5)
- exit
- ;;
- *)
- helploop
- ;;
- esac
- done
- }
- case "$1" in
- help)
- helploop
- ;;
- file)
- filoop
- ;;
- text)
- procloop
- ;;
- status)
- statloop
- ;;
- *)
- helploop
- ;;
- esac
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 19th, 2007, 6:52 am
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 1 post
- Users browsing this forum: No registered users and 181 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
