Skip to content

Instantly share code, notes, and snippets.

@jobscry
Last active December 31, 2015 14:18
Show Gist options
  • Save jobscry/7998888 to your computer and use it in GitHub Desktop.
Save jobscry/7998888 to your computer and use it in GitHub Desktop.
#!/bin/bash
choice=0
error1=" "
while true; do
clear
echo " Author: Bill Allen Menu 0"
echo
echo
echo "Current Directory: " $(pwd)
echo
echo
echo " Main Menu"
echo
echo " 1. List the names of the files"
echo " 2. List the names of the subdirectories"
echo " 3. List the contents of a file"
echo " 4. Move to a subdirectory"
echo " 5. Move to the parent directory"
echo " 6 . Exit to UNIX commands"
echo
echo
echo " " $error1
echo
echo -e " Enter the number of your choice: \c"
error1=" "
read choice
case $choice in
1 )
clear
count=$(ls -l | grep -v \/ | awk '{printf "%-20s %-10s %-4s\n", $8, $6, $5}' | wc -l)
if (( "$count" == "0" )); then
echo "Current Directory: " $(pwd) " Menu 1"
echo
echo
echo " There are no files in this directory "
echo
echo –e " Press Enter to return to the Main Menu\c"
read dummy ;;
else
echo "Current Directory: " $(pwd) " Menu 1"
echo
echo " Listing Name of Files"
echo
echo " File Name Date last Modified Size "
ls -l | grep -v \/ | awk '{printf "%-20s %-10s %-4s\n", $9, $6 " " $7 " " $8, $5}'
echo
echo " Total of " echo $count " files "
fi
echo
echo " Press Enter to Return to Main Menu"
read dummy ;;
2)
clear
countdir=$(ls -l | grep ^d | wc -l)
if test "$countdir"==0 then
echo
echo " Current Directory: " $(pwd) " Menu 2"
echo
echo " There are no subdirectories in this directory "
echo
echo
echo -e " Press Enter to return to the Main Menu\c "
read dummy ;;
else
echo
echo " Current Directory: " $(pwd) " Menu 2"
echo
echo " Listing Names of Subdirectories "
echo
echo " Subdirectory Name Date Modified "
ls -l | grep ^d | awk '{printf "%-20s %-20s\n", $8,$6}'
echo
echo " Total of " echo $count " subdirectories "
fi
echo
echo " Press Enter to return to Main Menu "
read dummy ;;
ls -l | grep ^d | awk '{printf "%-20s %-20s\n", $8,$6}'
clear
echo "sub-menu 2 selected"
echo –e "Press Enter to return to the Main Menu\c"
read dummy ;;
3)
clear
echo " Current Directory: " $(pwd) " Menu 3"
echo
echo " Listing the Contents of a File "
echo
echo
echo
echo "Enter the name of the file to list (or press Enter to return to Main Menu): "
read filename
read dummy ;;
ls -l | .temp0$$ #list out files in the directory and place them into a temp file
if ["$filename" != ".temp$$"] then echo "file does not exsist" #check to see if the file name is in the directory
if test -r$filename then ls -l -p $filename #test the file to check if there is read permission
else echo "you do not have access to read this file "
clear
echo " Current Directory: " $(pwd) " Menu 3"
echo
echo " Listing the Contents of a File "
echo
awk '1' $filename #list out the file
echo
echo "Enter the name of the file to list (or press Enter to return to Main Menu): "
read filename
read dummy;;
rm $filename #remove the temp file
echo –e "Press Enter to return to the Main Menu\c" #return to main menu
read dummy ;;
4 )
clear
echo " Current Directory: " $(pwd) " Menu 4"
echo
echo " Moving to a subdirectory "
echo
echo
echo
echo "Enter the name of the a subdirectory to move to (or press Enter to return to Main Menu): "
echo sub-menu 4 selected
echo –e "Press Enter to return to the Main Menu\c"
read dummy ;;
5 )
clear
cd ..
echo sub-menu 5 selected
echo –e "Press Enter to return to the Main Menu\c"
read dummy ;;
6 ) exit ;;
* )
error1 = "Please enter a number between 1 and 6"
esac
done
@jobscry
Copy link
Author

jobscry commented Dec 17, 2013

you don't need line #66, the if else if statement takes care of the program flow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment