EDIT2: @glenn jackman I thought this would fix it, but it still errs in my full script. Why isn't it working? Is it due to the indirect reference?
#!/home/$current_user/Desktop/expect
...
COUNTER=0
while [ $COUNTER -lt $num ]; do
let index=COUNTER+1
tmp=user_$index
echo "Changing Password for " ${!tmp}
echo ${!tmp}
sudo passwd ${!tmp}
expect -exact "[sudo] password for $current_user: "
send "$pass\r"
interact
expect -exact "New password: "
send "$password\r"
interact
let COUNTER=COUNTER+1
done
EDIT: The ! or the /$$ works for calling just variables inside of other variables. I need help for a case where the variable is part of a string.
I had a quick question regarding indirect variable references in Bash.
eval "\${user_$index\}" #First attempt
echo \$${eval "{user_\$index}"} #Second attempt
Basically I have several variables named "user_num" where the num is a integer. Each of these variables contains a String value. I want to call that string value by calling the variable. However, since the variable has a variable inside of it (num), I can't seem to get it working. I've looked through the Man pages for Indirect References in Bash, but they don't mention cases where the variable inside of another variable is attached to a string.
TLDR: My question is how do you do this:
$(var_$num)