I have a bash script which contains awscli as well. I am trying to print a variable which is created in a for loop. The variable that I am trying to print contains $ sign because of for loop. I couldn't print the value. Below I am sharing the script. The output of this script is only numbers which is generated in the for loop. I want to print the value which is generated in the command.
#!/bin/bash
declare -i counter=11
declare -i counter2=14
for i in {1..2}
do
declare v1$i=$(aws iam get-group --group-name VideoEditors | awk -v counter1=$counter 'NR==counter1' | awk -F\" '{print $4}')
counter=$counter+7
declare v2$i=$(aws iam get-group --group-name VideoEditors | awk -v counter3=$counter2 'NR==counter3' | awk -F\" '{print $4}')
counter2=$counter2+7
echo $v1$i
echo $v2$i
done
"${var}"
instead of just$var
;${x}${y}
instead of$x$y
. See unix.stackexchange.com/questions/4899/…$y
, which was identical to$x$y
. OP, my advice would be to use an array for v1 and v2 instead of v11/v12/v21/v22/etc.counter+=7
would do. Though I'm not sure if it would be more readable to just use$(( .. ))
with regular variables ...