Shell scripting help -- newbie
Hi,
Could someone help me with this....The following is the script that I have tried.. Write a Bourne shell script that allows the user to choose from 5 (five) menu options: 1. Print the users environment variables 2. display the number of subdirectories in a given directory and their listings 3. Files last modified in a specific month in a given directory 4. Make a backup copy for all the files created today 5. Exit the program Your script should allow the user to choose any option as many times as they wish. The menu should be redisplayed to the user after any option has finished executing, to enable them to make another choice. The final option, which terminates the program, can only chosen once and the menu should not be redisplayed after this option. If the user enters an incorrect choice, an appropriate error message should be displayed. Command Line Arguments The script should be able to accept only 2 command line arguments: • the first command line argument is to be the name of the directory in which your output file is placed. • the second command line argument is to be the name of a file in which the output are stored ############################################### #!/bin/sh selection=0 unfinished=0 while [$unfinished -eq 0] do echo Please Select on the following options echo echo "#####################################" echo 1. Print the user environment variables echo 2. Listing of Subdirectories and files contained in them echo 3, List files modified in a particular month and sort them by reverse echo order of the day echo 4. Backup of files echo 5. Exit the program echo "######################################" read selection case $selection in 1)echo date '+%d/%m/%y' | grep $USER /etc/passwd echo The user is $USER echo setenv echo Environmental Variables echo "Home Directory: $HOME" echo "Path: $PATH" echo "Mail Directory: $MAIL" echo "Login Shell: $SHELL" echo ;; 2)echo "Subdirectory listing" ls -alR ;; 3)echo "Please enter a valid month(Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec" read month if [$month =="Jan" -o $month =="Feb" -o $month =="Mar" -o $month="Apr" -o $month="May" -o $month="Jun" -o $month="Jul" -o $month="Aug" -o $month="Sep" -o $month="Oct" -o $month="Nov" -o $month="Dec"]; then echo Listing of files modified in '$month' by reverse order of day ls -al | grep $month | sort -n -r +7 else echo Please enter the first three letters of the month fi echo ;; 5)unfinished=1 ;; *)echo "Please enter a valid option number" ;; esac done ################################################ Thanks in advance. Cheers, RnJ |
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.
http://www.linuxquestions.org/rules.php And not only that, it also looks suspiciously like home-work to me. Break two rules in one post? |
All times are GMT -5. The time now is 04:23 AM. |