[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: doesnt interate the array anymore, what am i doing wrong
From: |
Greg Wooledge |
Subject: |
Re: doesnt interate the array anymore, what am i doing wrong |
Date: |
Sun, 7 Mar 2021 20:24:57 -0500 |
Alex fxmbsw7 Ratchev (fxmbsw7@gmail.com) wrote:
> bash-5.1# cat int.fail
> int() {
> declare -a int
You've declared a local array named "int" which has nothing in it.
This is inside a function named "int".
> declare i=-1 now
>
> while [[ -v int[++i] ]] && now=${int[i]} ; do
> printf %s\\n "$now"
> done
> }
You're iterating on the empty local array.
>
> int=( a b c )
> int
You also have a global array named "int".
I suggest that you use different names for your stuff. This will help
you avoid a lot of problems. Having a global variable, a local variable,
and a function all sharing the same name (and a name which is actively
*misleading* given that one of the arrays does not, in fact, contain
integer values) is not helping you.