I want to dynamically create a sequence of strings by manipulate an array of elements and create some arithmetic procedure.for name in FIRST SECOND THIRD FOURTH FIFTH; do    $name = $(( $6 + 1 ))    $name = ${$name}q;d    echo ${$name}; printf \ndoneThe desire outcome would be the below for $6 equals 0.1q;d2q;d3q;d4q;d5q;dBut I get this errorreel_first_part.sh: line 18: FIRST: command not foundreel_first_part.sh: line 19: ${$name}q;d: bad substitutionreel_first_part.sh: line 18: FIRST: command not foundreel_first_part.sh: line 19: ${$name}q;d: bad substitutionreel_first_part.sh: line 18: FIRST: command not foundreel_first_part.sh: line 19: ${$name}q;d: bad substitutionI guess it's something simple. It used to work when I did something like FIRST=$(( $6 + 1 ))FIRST=${FIRST}q;d
bash dynamic (variable) variable names
bash;variable
First of all there can not be any space around = in variable declaration in bash.To get what you want you can use eval.For example a sample script like yours :#!/bin/bashi=0for name in FIRST SECOND THIRD FOURTH FIFTH; do    eval $name='$(( $i + 1 ))q;d'    printf '%s\n' ${!name}    i=$(( $i + 1 ))donePrints :1q;d2q;d3q;d4q;d5q;dUse eval cautiously, some people call it evil for some valid reason.declare would work too :#!/bin/bashi=0for name in FIRST SECOND THIRD FOURTH FIFTH; do    declare $name=$(( $i + 1 ))q;d    printf '%s\n' ${!name}    i=$(( $i + 1 ))donealso prints :1q;d2q;d3q;d4q;d5q;d