|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
Hi all,
I'm relatively new to bourne shell scripting, and I'm trying to write a planner script. Code:
#! /bin/sh
# Option 2
# Get date from user
echo "Please enter day, month and year of event:"
read date
if [ $# -eq 3 ]
then
if [ $3 -lt date '+%Y' ]
then
echo Invalid year entered.
else
if [ $2 -le `date '+%m'`]
then
echo Invalid date entered.
else
if [ $1 -le `date '+%d'` ]
then
echo Invalid month entered.
else
# Get hour, minute and length from user
echo "Please enter hour, minute and length of event:"
read time
# Check that hour is valid.
if [ $1 -lt 0 -a -gt 23 ]
then
echo Invalid hour entered. Must be between 0 and 23 inclusive.
else
if [ $2 -lt 0 -o -gt 59 ]
then
echo Invalid minute entered. Must be between 0 and 59 inclusive.
else
# Get title from user
echo "Please enter a title for your event:"
read title
fi
fi
fi
fi
fi
else
echo Invalid number of arguments entered.
fi
Thats what I've got so far, which is to do with adding a entry to the planner datafile (planner.txt). I'm stuck with the bit about checking that the user entered the right number of arguments. I've gathered that $# can't be used to check for the number of arguments entered via read like they can straight to the script. Can someone point me in the right direction with this? Would also appreciate if someone could suggest any ways I could write what I've got in a better way. Seems a bit long and I'm sure there must be a better way. Hopefully someone can help. ![]() Also need some help with sorting the datafile for the planner. The entries are in the format: 16/08/2004 12:17 35 Some event 20/01/2005 13:25 17 some event 20/13/1900 22:00 17 some event 20/16/1925 13:15 25 some event 20/09/1986 13:56 25 some event and I want to sort them by year, month and then day. |
|
#2
|
|||
|
|||
|
Here are some tips that might help you out, or at least put you in the right direction:
PHP Code:
I find that it has also helps to wrap prompts/validations in while loops (eg. while not valid answer) so that fat fingered typing by the user doesn't cause them to start over from scratch. |
|
#3
|
|||
|
|||
|
For your sort problem, do check out the man pages on sort
(man sort) Some things to look for are how to set the field delimeter, in your case a "/". Then how to sort based on the 3rd, 2nd and 1st fields. Also check out the -o swicth so you don't have to use a temp file. Good luck. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Bourne Shell Scripting Assistance |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|