Skip to main content
Became Hot Network Question
shell variables are not necessarily environment variables.
Link
cas
  • 84.3k
  • 9
  • 136
  • 205

append iterator value to environment variable in for cycleloop

Source Link
Matteo
  • 283
  • 1
  • 8

append iterator value to environment variable in for cycle

I have a bash variable as such

HAP="$(echo ${d} | cut -f 7 -d '/' | sed 's/[A-Z,0-9]\+//' | sed 's/_//')"

that when is run as part of a script return either ref or hap. Now, I have another part of the same script where I'm running a step in a for loop which needs to be split into hap1 and hap2, respectively. So, ideally I will need something similar to the following:

for hap in [1:2]; do printf "%s\n" $HAP${hap}; done

that would return the value of $HAP twice appending to it the step of the iterator I'm at, resulting in something like:

hap1
hap2

However, the former loop gives this:

hap[1:2]

It is the first time I'm attempting this, and I'm not sure what is wrong... thanks in advance!