bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: doesnt interate the array anymore, what am i doing wrong


From: Alex fxmbsw7 Ratchev
Subject: Re: doesnt interate the array anymore, what am i doing wrong
Date: Mon, 8 Mar 2021 02:32:45 +0100

yea well i posted in a later post, locally declared vars are empty excepts
they are given on the function calling line, just like local vars, hm
the different names is not so a good idea but ill think

thank you much anyway :))

On Mon, Mar 8, 2021 at 2:25 AM Greg Wooledge <greg@wooledge.org> wrote:

> 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.
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]