naming variables with variables

Hello,

FIRST QUESTION:

I am writing a script in which a query is taken at the beginning of the script to be later used at the end. In the query, variables are generated from a loop, and I would like to assign the variable NAME (not value) with an appended 1, 2, 3, 4.....n. The number of loops varies according to the circumstance.

So for example, I get:
$pattern1, $pattern2, $pattern3...etc

The problem I have is that these variables are used later in the script in a loop, in which the first pass of the loop needs to call the first $pattern1, the second pass should call $pattern2, etc.

How do I dynamically call each variable in its sequence?

If I try something like incrementing a variable called "pass" each time, and then appending it to pattern:

$pattern$pass

I merely get the concatenation of the two (which simply is the value of $pass, since $pattern is not set).

I have tried things like:

${pattern$pass}

but only get errors.

Any ideas on how to call variables in this way?

SECOND QUESTION

At the beginning of the script where I am originally assigning values to the $pattern/n variables, I am also naming them dynamically, using

let pattern$pass=value

so when pass=1 I end up with a variable called pattern1 with the value of value.

(simply typing pattern$pass=value does not work, I had to explicitly use the let command.)

This works fine, but I run into trouble when I want to place forward slashes around value in order to substitute it in a sed script, eg,

let pattern$pass=/value/

I get an error from let saying operand expected.

Does anyone know how I might accomplish this?

I can work around this one, but I would rather find out how to do what I want to do.Thank you,

Allasso

you can use 'eval' to solve ur problem...

1 Like

thank you. Someone pointed me to using an array, and I think that is going to do exactly what I want.