LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 09-12-2005, 12:28 AM   #1
rnj
Member
 
Registered: Sep 2004
Location: Australia
Distribution: Fedora Core 2
Posts: 36

Rep: Reputation: 15
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
 
Old 09-12-2005, 01:08 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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?
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 03:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 04:32 PM
Shell Scripting again yaadhav Linux - Newbie 8 08-04-2005 11:21 AM
Shell Scripting kidestranged Linux - General 5 07-28-2004 12:46 AM
Shell Scripting problems (newbie) yawgmoth81 Programming 11 02-24-2003 03:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration