0

Random Variables

VARA=('blah')
VARB=('blah2')
VARC=('blah3' 'alt_blah3')

MASTERVAR=${VARA}${VARB}${VARC[0]}
ULTIMATEVAR=${VARA}${VARB}${VARC[1]}

What I want: An Array that references MASTERVAR and ULTIMATEVAR.

ULTIMATEMASTERVAR=(${MASTERVAR} ${ULTIMATEVAR})

What I've tried.

ULTIMATEMASTERVAR=('${MASTERVAR}' '${ULTIMATEVAR}')
ULTIMATEMASTERVAR=(${!MASTERVAR} ${!ULTIMATEVAR})

Wanted Result:

echo ${ULTIMATEMASTERVAR[0]}

Which prints out

blahblah2blah3
  • If you are just going to use `${VARA}` and not `${VARA[0]}`, you don't need to use parentheses to assign to it: `VARA='blah'`. – chepner Apr 19 '18 at 16:56

1 Answers1

0

How to refer to other variables in an array:

$ foo=(abc)
$ bar=(def)
$ all=(foo bar)
$ echo "${all[0]}"
foo
$ echo "${!all[0]}"
abc

Loop through all to get the first element of each of them.

l0b0
  • 55,365
  • 30
  • 138
  • 223