Bash menu
- mo_mughrabi
- Student


- Inscription: Nov 07, 2006
- Messages: 73
- Status: Offline
Bonjour,
Je travaille sur un menu shell en utilisant Solaris (Unix) et quand je me suis déplacé le code pour linux redhat son ne fonctionne pas correctement. Je ne suis pas sûr de ce que doit je mettre à jour dans le code,, s'il vous plaît aider
#!/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 '}`"
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 "" in
help)
helploop
;;
file)
filoop
;;
text)
procloop
;;
status)
statloop
;;
*)
helploop
;;
esac
Je travaille sur un menu shell en utilisant Solaris (Unix) et quand je me suis déplacé le code pour linux redhat son ne fonctionne pas correctement. Je ne suis pas sûr de ce que doit je mettre à jour dans le code,, s'il vous plaît aider
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 '}`"
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 "" 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 '}`"
- 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 "" in
- help)
- helploop
- ;;
- file)
- filoop
- ;;
- text)
- procloop
- ;;
- status)
- statloop
- ;;
- *)
- helploop
- ;;
- esac
- Anonymous
- Bot


- Inscription: 25 Feb 2008
- Messages: ?
- Loc: Ozzuland
- Status: Online
Mai 19th, 2007, 6:52 am
Page 1 sur 1
Pour répondre à ce sujet, vous devez vous connecter ou vous enregistrer. Il est gratuit.
Afficher de l'information
- Total des messages de ce sujet: 1 message
- Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 68 invités
- Vous ne pouvez pas poster de nouveaux sujets
- Vous ne pouvez pas répondre aux sujets
- Vous ne pouvez pas éditer vos messages
- Vous ne pouvez pas supprimer vos messages
- Vous ne pouvez pas joindre des fichiers
