My bash masterpeice is almost complete ... I have one last problem that no matter how many "" or '' I use I cannot get around.

I need to use an if...then construct to check that my 4 digit date field is 4 numerical digits.This is for error checking. I thought [sets] was the way to go ....

if [ $fourdig = [0-9][0-9][0-9][0-9] ]; then ......

I have tried '[0-9]' "[0-9]", straight [0-9]. Interestingly no matter what I do in [sets] as a comaparison it is invalid in the if...then construct. It has occured to me that perhaps [sets] are not allowed as a conditional test.

If this is the case, how can I test a string ?

Dave








#!/bin/sh


# Remind script v1.0 23rd June 2003 Dave Selby


calender=/mnt/archive/remind/calender/ toX=/mnt/archive/remind/toX/ mmddfile=/mnt/archive/remind/mmdd

header='\nThis is a reminder message from "remind" v1.0 23rd June 2003\nTo change the calender cd /mnt/archive/remind/calender\n\n'



# Displays a remind screens in eye catching red !
remindscreens ()
{

# Scans the /mnt/archive/toX dir, displays all remind screens
for toXfiles in $(ls $toX); do

echo -e -n $header'File :'$calender$toXfiles'\n\n'$(cat $toX$toXfiles) | xmessage -fn 9x15 -center -buttons OK,Print,Delete -default OK -bg red -file -
case $? in
102) echo -e -n '\n\n\n'$header'File :'$calender$toXfiles'\n\n'$(cat $toX$toXfiles) | lpr;;
103) rm $toX$toXfiles;;
esac
done
}



nowmmdd=$(date '+%m%d')


# Get value of mmdd if it exists, else set it to 0101
if [ -e $mmddfile ]; then
   oldmmdd=$(cat $mmddfile)
else
   oldmmdd="0101"
fi


# Abort if this is not the first run of the day
if [ ! $oldmmdd -eq $nowmmdd ]; then
# Scans $calender, if files are in date range, copy them to $toX
for calfile in $(ls $calender); do


   fourdig=${calfile:0:4} # Strip off date
   if [ $fourdig -gt $oldmmdd ] && [ $fourdig -le $nowmmdd ]
   then
        cp $calender$calfile $toX
   fi

done

# Update mmddfile to now, ready for tomorrow !
echo $nowmmdd > $mmddfile
chmod a=rwx $mmddfile

remindscreens &

fi





--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




Reply via email to