1

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.

3
  • 2
    I assume in your original you don't have spaces around the equals (=)? I ran your script and it ran fine, although the for CNT... loop starts with CNT value of 1, but you probably intend 0. It does otherwise show the defined values of both $a and $BIT. Commented Feb 26, 2015 at 12:07
  • 2
    as @lurker says, I hope you equal signs are good. I don't see any problem otherwise. To avoid computing the $a, you could try for CNT in $( seq 0 31) and your problems will go away (as @lurker says, you will have the proper array entry and no need to compute $a, just use $CNT) Commented Feb 26, 2015 at 12:17
  • 1
    Thanks luker and tgo. Problem has been resolved. Commented Feb 26, 2015 at 12:21

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

I can't see how this resolved your issue. The $BIT variable isn't set anywhere, and VAL[0] =1 isn't valid Bash code due to the space.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.