How can I increment a variable already defined in bash? Here's what I mean:
ID1="YAY1"
ID2="YAY2"
for (( c=1; c<=3; c++ ))
do
if [ "$SOMEOTHERVAR" = "ID$c" ]; then BLAH; fi
done
Problem is, when it increments the variable already defined to do the comparison, it thinks ID$c is equal to the string ID1, not what ID1 equals which is YAY1, so the if statement always evaluates false. I hope that makes sense.
Thank you for your help!
******UPDATE******
Thanks everyone for your help. The cleanest solution was to use a single array mixed with cut. May not be the cleanest way, but works great. Here is a snippet below:
# CONTACTS
declare -a EMAIL
EMAIL[1]="JS:[email protected]"
EMAIL[2]="JD:[email protected]"
EMAIL[3]="JK:[email protected]"
# FUNCTIONS
function EMAIL {
for i in "${!EMAIL[@]}"; do
POINTER="`echo ${EMAIL[$i]} | cut -d":" -f1`"; ADDRESS="`echo ${EMAIL[$i]} | cut -d":" -f2`";
if [ "$POINTER" = "$PEMAIL" ]; then TO="$ADDRESS"; fi
if [ "$POINTER" = "$SEMAIL" ]; then CC="$ADDRESS"; fi
done
}
PEMAIL and SEMAIL are the comparators which are pulled from the database in another part of the script.