Last active
December 31, 2015 14:18
-
-
Save jobscry/7998888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
if statement on line #33 should look like this:
if (( "$count" == "0" )); then
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
the while loop should probably be:
while true; do