Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to range check korn passed parameters 1

Status
Not open for further replies.

sblomley

Technical User
May 17, 2001
1
GB
Hi,
I was wondering if I could get a little help with some korn shell that I cant get quite right.

I want to range check the first 2 parameters so that they are both within the rance 0-23 and that the $GO is less than $STOP before I do anything with the script.

If there is a problem then just report the problem and exit. I thought I could do it in a 1-liner but I'm loosing the plot.

Please could someone review the following and advise.

GO=${1:-3}
STOP=${2:-18}

[[ ${GO}>=0 || ${STOP}<24 ]] && { print &quot;Failed 0 <= START <= 24&quot;; exit 1; }
[[ ${STOP}>=0 || ${STOP}<24 ]] && { print &quot;Failed 0 <= FINISH <= 24&quot;; exit 1; }
[[ ${GO}<${STOP} ]] && { print &quot;Failed START < FINISH&quot;; exit 1; }

Many Thanks
Stephen
 
Stephen:

First, if you are going to compare arithmetic expressions in ksh, you need to use the double parenthesis as shown.

Second, I'm interpeting that if GO is less than 0 or stop is greater than 24 or go greater than stop, then error out.

I hope this is what you want,

Ed

#!/bin/ksh

function usage {
print $1
exit 1
}

GO=${1:-3}
STOP=${2:-18}
echo $GO
echo $STOP

((GO<0 || STOP>24 || GO>STOP)) && usage &quot;FAILURE&quot;

#((GO>=0 || STOP<24)) && usage &quot;Failed 0 <= START < 24&quot;
#((STOP>=0 || STOP<24)) && usage &quot;Failed 0 <= FINISH <= 24&quot;
#((GO<STOP)) && usage &quot;Failed START < FINISH&quot;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top