Thank you paulsm4 and grail, both of your suggestions were invaluable to the solution! Paul, your suggestion of: sn_array[0]=”A” {etc.} was confusing since “A” wasn’t defined. In incorporated your echo suggestion in the loop, I discovered through the error message that the correct digits were loading into the right spot…great job on that! Next, Grail, the reason for the test brackets was I thought they had to be there…I’m very new with Linux and bash. But your suggestion made my code cleaner! As for the solution…well I had to use n as a variable for the length rather than the digit 1...and off it went.
Thanks to you two, my code not only works, but it’s cleaner.
Thanks from a grateful newbie! Oh, and here’s the working code:
Quote:
#Testing formatting input for mm
FLOOR=1000 #bottom limit of secret number
CEILING=9999 #upper limit of secret number
while ((secret < FLOOR)) #obtaining bottom range
do
secret=$RANDOM
((secret %= CEILING)) #number is now 4 digits long
done
declare -a sn_array #defines sn_array[ ]
for ((si = 0; si <= 3; si++ ))
do
n=1
sn_array[si]=${secret:$si:$n}
done
echo $secret
echo ${sn_array[@]}
|
Output of last run:
3957
3 9 5 7