I don't know exactly how to ask this in English, but I want to have the value of a variable as a new variable... The script also has a loop with increasing numbers, and in the end I want to have the variables VAR1, VAR2 etc.
I'm trying this:
COUNT=$(echo 1)
DEFINE=$(echo VAR$COUNT)
$DEFINE=$(echo gotcha!)
When I try this way, I have this error message:
~/script.sh: line n: VAR1=gotcha!: command not found
I played a bit around with brackets and quotation marks, but it didn't work... any solutions?
bash. Why aren't you instead usingbasharrays?echoin a command substitution? this is really silly. Use this instead:count=1,define=var$count. Now for the last one, you may useprintf -v "$define" '%s' 'gotcha!'.