Can i get this value in this variable [Linux Bash] my code
#!/bin/bash
COUNTER=1
"user$COUNTER"=text
echo "$user$COUNTER"
result : 1 i need result : text
The trick is eval
eval user$COUNTER=text
Output:
/home/shellter:>eval "user$COUNTER"=text
/home/shellter:>echo $user1
text
Eval performs variable evaluations any visible variables on the command line, and then 'resubmits' the results to normal command-line evaluation and processing.
You can see some of this happening (once you have worked with for a while it will become obvious) by turning on the shell debugging with set -vx.
I hope this helps.
P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.
eval echo $user$COUNTER -- you have to eval any time you want to dereference the "compound" variable.