Defining Dynamic Number of Variables in a Bash Script

Code:

$ cat test.bash
#!/bin/bash

job=$1
steps=$2

num=$(echo "$@" | wc -w)

Example Submission:


$ ./test.bash BS01 3 1 2 3

What:
I want to be able to take the number of $2 (steps) and then define the substeps ($3++) for each step.

i.e. the submission of the above would define the following variables

job BS01
steps 3
substep1 1
substep2 2
substep3 3

I don't know how to create the substeps?

I was thinking about stepping through the $@ using the num variable I setting the substeps in the loop.

countera=3
counterb=1
while [ $counter -le $num ]; do
 substep${counterb}=eval \$$countera
 countera=countera+1
 counterb=counterb+1
end;

Of course, this doesn't work at all, but it's the closest my inexperience can take me.

Any help is appreciated!

Thanks

Try something like this:

#!/bin/ksh

i=1
job=$1
steps=$2

shift; shift

while [ $i -le $steps ]
do
  eval "substep${i}=$1"
  shift
  i=$(( $i + 1 ))
done

echo $job
echo $substep1
echo $substep2
echo $substep3

Thanks that worked well.