Shell script to list out the contents of a file
This shell script will list out the contents of a file using MENU DRIVEN, considering the following:
- The user enters the file name (may enter a path)
- The script reads in the file name
- It checks if it exists and it is a file
- If it does not, it warns the user
- Otherwise it should list the contents
# !/bin/bash
# MENU DRIVEN BASH SCRIPT CREATED BY Nathan Joseph (http://NJ180degree.net)
# CREATED ON APRIL 30th 2010
# ISSUED UNDER THE GNU GPL (GNU GPL)
echo "Hello $USER, Welcome to THE CONTROL MENU"
echo "The Date & Time is:"
date
function FILE {
echo -e "Please enter a file name"
read FILE
if [ ! -f $FILE ]
then
echo -e "Error: The file $FILE does NOT exists!"
else
cat "$FILE"
echo -e ""
fi
}
echo -e "Please choose from the following options by entering 0 or 1"
echo -e "1. List out the contents of a file!"
echo -e "0. Exit"
read option
while [ "$option" != "0" ]
do
case $option in
1) FILE ;;
*) echo -e "Invaild choice, please choose from 0 or 1 only" ;;
0) echo " "
echo -e "0.Exit the program"
exit 0
;;
esac
echo -e "Please press return to go back to the main menu"
read RETURN
echo -e "Please choose from the following options by entering 0 or 1"
echo -e "1. List out the contents of a file!"
echo -e "0. Exit"
read option
done
echo -e "Thanks for using my script.. you may change or modify it to suit your purposes :)"
exit
Related posts:
| Print article | This entry was posted by Nathan on 29/04/2010 at 10:45 pm, and is filed under Scripts, Shell script. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |






