Stopping a shell script

This is simple for an experianced scripter but that is not what I am :slight_smile:

if [ $End_Date != '-' -a $End_Date > $Start_Date ]; then
     echo -==Test Passed $3 $4==- >> $1$2
     nohup $6$7 & >> $1$2
     else
     echo -==$8==- >> $1$9
     echo -==$8==- >> $1$2
fi

In the else step I also want to stop the script from moving on. What is the command for that?

use 'return'

Great thanks for the help

I tried your suggestion without success

if [ $End_Date != '-' -a $End_Date > $Start_Date ]; then
		echo -==Test Passed $3 $4==- >> $1$2
		nohup $6$7 & >> $1$2
	else
     echo -==$8==- >> $1$9
     echo -==$8==- >> $1$2
     return
fi 

What did I do wrong?

use exit to stop the execution of a script

Use exit with an exit code to indicate success or failure
0 : success
anything but 0 : failure

I have neaver set up error traping before. Can you give me a simple example?

You can't do this:
if [ $End_Date != '-' -a $End_Date > $Start_Date ]; then

OK, you can do that, but you are redirecting the output of the [ command into a file named for your start date with "> $Start_Date" and your test is:
if [ $End_Date != '-' -a $End_Date ]; then

This collapses to testing if $End_Date is null or not.

All of this is legal, but possibly not what you intended.

You make a good point.

What I want to do is make sure that the End_date is larger than the Start_Date. What is the operand for that?

-gt

You can do "man test" to all of the options.

The -gt option looks for intigers, but I have a date.

How do I get test to evaluate dates?

The test(1) utility cannot handle dates. I suggest you convert your dates to the Julian format i.e. integers and then use test to compare these integers

Here is a pointer to an SysAdmin article on the subject:

Sys Admin > v12, i07: Date Arithmetic with the Shell

-gt can handle large integers. If the date is YYYYMMDD format, it should work.

I need time as well...will this still be true if I do:

YYYYMMDDHHMMSS

Looks like it worked....

-==Testing 'RKEM REFRESH' 'RKEM REFRESH - UPDATE' Tue Jan 1 15:22:07 UTC 2008==-
-==20071231214856 ==-
-==20071231221557 ==-
-==Test Passed 'RKEM REFRESH' 'RKEM REFRESH - UPDATE'==-

Ok the -gt is now working but i need to test to see if my variables are null before i test the -gt, how do you do multiple test in one line? Is it something like this?

[ $variable -n $variable1 -gt $variable2 ]