So I am making a script that allows you to input a number, export it, and then import it and use it in a loop. Here's what I mean:
read NumberOfVMs "How many do you want? "
echo $NumberOfVMs > /variables/NumberOfVMs
Then later;
while [ $NumberOfVMs -gt 0 ];do
# This is the loop I use to repeat the effects I want.
# This method works fine for me.
NumberOfVMs=$((NumberOfVMs-1))
done
However, what gets me is that I need to use variables that are listed by number (based on what $NumberOfVMs is equal to. I also want to zero pad the number to four 0s. I know I can zero pad by doing $(printf %04g $NumberOfVMs)
.
For example, I want to be able to make 3 variables (respectively with 0001, 0002, and 0003 added to the end of the variable name) when asking a question. I am currently doing it like this
while [ $NumberOfVMs -gt 0 ];do
read -p "Enter percentage of RAM to allot GuestOS (1-99): " percentram$(printf %04g $NumberOfVMs)
NumberOfVMs=$((NumberOfVMs-1))
done
and, while I do believe (I might be wrong) that say, percentram0001, is being written - I cannot figure out how to use it dynamically when using the variable as
$percentram$(printf %04g $NumberOfVMs)
would not equal percentram0001
but rather equal the output of percentram
with 0001 added to it.
Please, if you could help me out I'd love you forever.