How to do indirect variable evaluation
You can use bash indirect references for that:
AR1_p1=22
AR1_p2=23
AR1_p3=24
AR1_p4=25
for i in 1 2 3 4
do
VARNAME="AR1_p${i}"
echo "${!VARNAME}"
done
Per suggested comment(s), array should be used:
#!/bin/bash
AR1_p=(22 23 24 25)
for i in {1..4}
do
echo "${AR1_p[$i-1]}"
done
This loop works. Else use Arrays.
$ for i in 1 2 3 4; do AR1_p1=22; AR1_p2=23; AR1_p3=24; AR1_p4=25; echo $((AR1_p$i)); done
22
23
24
25