KSH convert case to for loop or other

Hi

I have a case statement that work great but now I need to make it dynamic.

Have a input into the script    <script name>.ksh AAA TEST:5

the current script is

#!/bin/ksh

A1=`echo $2 | awk -F: '{print $1}'`
A2=`echo $2 | awk -F: '{print $2}'`

echo "A1 = $A1"
echo "A2 = $A2"

AA=`ecaqrtab list $A1 | grep $A1 | awk '{print $2}'`

  case $AA in  
   4)
       ecaqrtab update $A1 5
       ;;  
   3)
       ecaqrtab update $A1 4
       ;;  
   2)
       ecaqrtab update $A1 3
       ;;  
   1)
       ecaqrtab update $A1 2
       ;;  
   0)
       ecaqrtab update $A1 1
       ;;  
  esac





The max for the case would be dynamic so with the input "TEST:5", 5 is the max and in the current case statement I have up to 4) hard coded. The number 5 will change. It could be any number.

So I am not sure how to dynamically set the case statement to adjust for this.

The case is always the max-1 for the starting value. Example:    5-1=4   the first value in the case is  4)

The $AA gets back the current value which could be 0 thru 4   or if other than 5 max it depends on the max.

Hope this explains it.

Thanks
LVL 1
mikeysmailbox1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gerwin Jansen, EE MVETopic Advisor Commented:
case only selects one based on the input and since you have no other (final) statement for the case you can just call your update with $AA+1 - no case needed

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikeysmailbox1Author Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.