Scope of variables in bash script
<p>I am using the variable "i" three times in the following simple bash script which essentially generates random numbers which are not there in an array. Can someone help me understand the scope of each of these variables here? </p>

<pre><code>timestamp="9"
researchArea="5"
numberOfDimensions="8"


timeStampToInjectArray=()
dimensionToTamperArray=()
for((i=0;i&lt;$numberOfDimensions;i++))
do     
    echo $i
    while : ;
    do

        timeStampToInject=$(shuf -i 0-$timestamp -n 1)
        dimensionToTamper=$(shuf -i 1-$researchArea -n 1)
        flag=0
        for((i=0;i&lt;${#timeStampToInjectArray[@]};i++))
        do
            echo $i
            if [ "${timeStampToInjectArray[i]}" -eq "$timeStampToInject" ] &amp;&amp; [ "${dimensionToTamperArray[i]}" -eq "$dimensionToTamper" ]; then
            flag=1
            fi
        done
        if [ "$flag" -eq "0" ]; then
            break
        fi

    done
    timeStampToInjectArray+=("$timeStampToInject")
    dimensionToTamperArray+=("$dimensionToTamper")
    echo $timeStampToInject,$dimensionToTamper
done
</code></pre>