Delibz Delibz - 6 months ago 8
Bash Question

Why does this script runs improperly?

So sorry for my carelessness....the second version runs properly now.

But I am still confused with the first issue:

#!/bin/bash

for((i=1;i<=50;i++))
do
sum=$((sum+i))
done
echo $sum


Then sh 6.sh:

enter image description here

Why could this happen...

Since the original version was rewritten, I cannot reproduce this issue too...What may cause that issue?

Answer

Please check your for line. It seems it has mix of i, l and 1. Please try this:

 for((i=1;i<50;i++))
Comments