I'm starving trying to make the following thing work:#!/bin/bashMARCOMIN=1MARCOMAX=3ENZOMIN=1ENZOMAX=3GIOVANNIMIN=1GIOVANNIMAX=3VALUEMARCO=12VALUEGIOVANNI=4VALUEENZO=12for i in MARCO ENZO GIOVANNI; do        echo $$iMIN is $i\'s MIN        echo $$iMAX is $i\'s MAX        echo $VALUE$i is $i\'s VALUEdoneexit 0It doesn't writes macro as I'd like, though.me@myhost:~$ bash test.sh20341iMIN is MARCO's MIN20341iMAX is MARCO's MAXMARCO is MARCO's VALUE20341iMIN is ENZO's MIN20341iMAX is ENZO's MAXENZO is ENZO's VALUE20341iMIN is GIOVANNI's MIN20341iMAX is GIOVANNI's MAXGIOVANNI is GIOVANNI's VALUEObviously this is only one of my test. I tried many different ways of writing macros this way but I can't fix it. Found many similar questions here and on SO, but none matched my case.bash -x test.sh follows:+ MARCOMIN=1+ MARCOMAX=3+ ENZOMIN=1+ ENZOMAX=3+ GIOVANNIMIN=1+ GIOVANNIMAX=3+ VALUEMARCO=12+ VALUEGIOVANNI=4+ VALUEENZO=12+ for i in MARCO ENZO GIOVANNI+ echo 21466iMIN is 'MARCO'\''s' MIN21466iMIN is MARCO's MIN+ echo 21466iMAX is 'MARCO'\''s' MAX21466iMAX is MARCO's MAX+ echo MARCO is 'MARCO'\''s' VALUEMARCO is MARCO's VALUE+ for i in MARCO ENZO GIOVANNI+ echo 21466iMIN is 'ENZO'\''s' MIN21466iMIN is ENZO's MIN+ echo 21466iMAX is 'ENZO'\''s' MAX21466iMAX is ENZO's MAX+ echo ENZO is 'ENZO'\''s' VALUEENZO is ENZO's VALUE+ for i in MARCO ENZO GIOVANNI+ echo 21466iMIN is 'GIOVANNI'\''s' MIN21466iMIN is GIOVANNI's MIN+ echo 21466iMAX is 'GIOVANNI'\''s' MAX21466iMAX is GIOVANNI's MAX+ echo GIOVANNI is 'GIOVANNI'\''s' VALUEGIOVANNI is GIOVANNI's VALUE+ exit 0
How can I use the expanded value of a shell variable in the name of another variable?
bash;shell script;variable
Bash supports variable indirection:#!/bin/bashMARCOMIN=1MARCOMAX=3ENZOMIN=1ENZOMAX=3GIOVANNIMIN=1GIOVANNIMAX=3VALUEMARCO=12VALUEGIOVANNI=4VALUEENZO=12for i in MARCO ENZO GIOVANNI; do    for j in MIN MAX VALUE; do        varname=${i}${j}        # For VALUE we need reverse order of i and j        [[ $j = VALUE ]] && varname=${j}${i}        printf %d is %s's %s\n ${!varname} $i $j    donedoneexit 0I did a little extra with the inner loop and use of printf in place of echo but the central idea is that given a variable name foo stored in another variable bar you can get the value of $foo by doing ${!bar}.More: https://stackoverflow.com/questions/8515411/what-is-indirect-expansion-what-does-var-mean