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
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