On Sat, Jul 26, 2025 at 11:22:47AM +0200, Dan wrote:
> y=0
> arg[$y]="hello"
> y=$y+1
> arg[$y]="dan"
This piece of code doesn't do what you probably think it does.
Although it works here, y is a string variable and not a numeric variable.
If you add some extra echo statements you can see:
> y=0
> arg[$y]="hello"
> y=$y+1
echo $y
> arg[$y]="dan"
The content of $y is the string '0+1'.
The following assignment to arg[] correctly evaluates the 0+1, so it works
_in this case_, but you should probably be using _let_ :
let y=0
instead of
y=0
and elsewhere where you want to ensure that y is a numeric variable.
No comments:
Post a Comment