declare, assign variables using array, counter, loop

using bash Tru64...

converting DCL to shell...

any tips to make this work would be greatly appreciated.

Below is my failed attempt to assign command line input to variables by first declaring an array. I use a counter to create unique variables in a loop through the array. I need to call the newly created variables in functions, hence the export.

When I run the script I receive the following error...

./newfile1.shl: param1=1: command not found
./newfile1.shl: param2=2: command not found
./newfile1.shl: param3=3: command not found
./newfile1.shl: param4=4: command not found
./newfile1.shl: param5=5: command not found

#!/bin/bash
LIMIT=6
PARAM="$1 $2 $3 $4 $5"
COUNTER=1

while [ $COUNTER -lt "$LIMIT" ];
do
for n in ${PARAM[@]}
do
param$COUNTER=`echo $n`
export param$COUNTER

let COUNTER=COUNTER+1

    done

done

echo $param1
echo $param2
echo $param3
echo $param4
echo $param5

This code looks very strange and I'm not able to imagine what result you're attempting to achieve.

But to set up an array in bash it's:
PARAM=($1 $2 $3 $4 $5 $6)

I *think* that you need ti increment the counter between the two done statements.

It is possible that you want:
eval param$COUNTER=$n
but I'm not real sure.

Also an instance of bash will be running this script. That instance of bash will be a process. If you run export commands in the script, you will affect the environment of the process that is running your script. This environment will be inherited by any child processes you launch. But when the script ends, so process will exit. This environment is gone. You will probably go back to an interactive shell with its old unchanged environment.

The arguments kind of come into the shell script as an array -
$@ is all of them, $# is the number of arguments. Some of the folks here still read DCL, you may want to post the parts of your code you're having problems with.

To get the arguments to show up in a loop you could try something like this:

echo "args = $@"
let i=0
for arg in `echo $@`
do
   echo "Argument $i = $arg "
   let i=i+1
done

Seems that the bash way to build an array to contain the script's parameters is simply...

declare -a param="$@"

See the Advanced Bash-Scripting Guide: Chapter 26. Arrays