May 19, 2009 #1 gkd MIS Jun 20, 2000 25 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.
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.
May 19, 2009 1 #2 PHV MIS Nov 8, 2002 53,708 FR What have you tried so far and where in your code are you stuck ? Hope This Helps, PH. FAQ219-2884 FAQ181-2886 Upvote 0 Downvote
What have you tried so far and where in your code are you stuck ? Hope This Helps, PH. FAQ219-2884 FAQ181-2886
May 20, 2009 Thread starter #3 gkd MIS Jun 20, 2000 25 SG 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 Upvote 0 Downvote
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
May 20, 2009 #4 PHV MIS Nov 8, 2002 53,708 FR 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 Upvote 0 Downvote
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
May 20, 2009 1 #5 fpmurphy Technical User Mar 2, 2004 93 US 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 Upvote 0 Downvote
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