简体   繁体   中英

Print values of arrays inside for loop using bash

I am trying to print the $a and $BIT values.

But I'm receiving the value of $BIT but not $a.

Please find the code as follows,

echo "Content-type: text/html"
echo ""
echo "<html><head><META HTTP-EQUIV='refresh' CONTENT="1"></head>"
VAL[0] =1;
VAL[1] =0;
VAL[2] =1;

for CNT in $(seq 32)
do
    BIT = ${VAL[$CNT]};
    a = $(($CNT-1));

echo "<p>$a,$BIT</p>";
done

Please help me on this.

Thanks in advance.

I have changed my code like below. My issue got resloved.

    echo "Content-type: text/html"
    echo ""
    echo "<html><head><META HTTP-EQUIV='refresh' CONTENT="1"></head>"
    VAL[0]=1;
    VAL[1]=0;
    VAL[2]=1;

    for CNT in $(seq 0 31)
    do
        a=$CNT;

    echo "<p>$a,$BIT</p>";
    done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM