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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

korn shell testing input parameters 2

Status
Not open for further replies.

gkd

MIS
Jun 20, 2000
25
0
0
SG
Frieds,
./script.ksh $1 $2

i want to run a korn shell script only if $1 is equal to report or run and if $2 any number greater than zero.

Can someone advise me the efficient way to write this script.
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Here is the script that i have. it is fine, but is there a better way to do it?

#!/bin/ksh
if [ $1 = report ] || [ $1 = run ] && [ $2 -gt 0 ]
then
echo "This is correct: $0 $1 $2"
else
echo "USAGE:$0 <report|run> <number> "
fi
 
What about this ?
Code:
#!/bin/ksh
[ $# -eq 2 -a \( "$1" = report -o "$1" = run \) -a "$2" -gt 0 ] || {
  echo "USAGE:$0 <report|run> <number>"; exit 1
}
echo "This is correct: $0 $1 $2"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here is another way - using ksh93 regular expressions
Code:
if [[ $1 =~ ^(report|run)$  &&  $2 > 0 ]]
then
   echo "This is correct: $0 $1 $2"
else
   echo "USAGE:$0 <report|run> <number> "
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top