help-bash
[Top][All Lists]
Advanced

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

Re: Using Associative Arrays declared in functions


From: Alex fxmbsw7 Ratchev
Subject: Re: Using Associative Arrays declared in functions
Date: Tue, 13 Apr 2021 21:43:20 +0200

look, this is an incomplete answer of me

color codes and efficiency are big topics
tput commands i dont know tho

id prolly alias much on a str stack and end-printf when needed
but again, i dont know enough of this topic

peace

On Tue, Apr 13, 2021, 21:13 <michael-franzese@gmx.com> wrote:

> I'd like your point of view on calling functions
>
> As described, I have a file 'colr-tools.sh' with functions for colouring
> text
> in terminal windows.
>
> Then I have two other files that I am using to run some tests.  One of the
> files is 'colr-fractr.sh', where I have same functions with tests that call
> the function tools for colouring declared in 'colr-tools.sh'.
>
> Then, another file 'colr-tests.sh' that has the main calling sequence
> on what tests to run, based on the idea of 'main' in c-programs.
>
> In 'colr-fractr.sh', I have the function 'scout-terminfo-colours'
> that call tho associative arrays in 'colr-tools.sh'.
>
> This is the way I am doing the calls in 'colr-tests.sh'
>
> ----- colr-tests.sh -----
>
>   source ${tools_path}/colr-tools.sh
>
>   # this defines the colour arrays in colr-tools.sh
>   termi-colr-wheel
>
>   # this calls the test that use the array variables in 'colr-test.sh'
>   source ./colr-fractr.sh
>
>   # this runs the test function in 'colr-fractr.sh'
>   scout-terminfo-colours
>
> ----- colr-tests.sh -----
> I also have the possibility to call 'source ${tools_path}/colr-tools.sh'
> in the file 'colr-fractr.sh' rather than in 'colr-tests.sh'.  Where
> would your prefer having tho call to 'source ${tools_path}/colr-tools.sh',
> in 'colr-fractr.sh' or in 'colr-tests.sh'.
>
> Regards
>
> > Sent: Wednesday, April 14, 2021 at 6:15 AM
> > From: "Alex fxmbsw7 Ratchev" <fxmbsw7@gmail.com>
> > To: michael-franzese@gmx.com
> > Cc: "help bash" <help-bash@gnu.org>
> > Subject: Re: Using Associative Arrays declared in functions
> >
> > np yo, glad i did help
> >
> > On Tue, Apr 13, 2021, 19:24 <michael-franzese@gmx.com> wrote:
> >
> > > Using -g works like a gem.
> > >
> > > My hat off to you Alex. :)
> > >
> > > > Sent: Wednesday, April 14, 2021 at 4:31 AM
> > > > From: "Alex fxmbsw7 Ratchev" <fxmbsw7@gmail.com>
> > > > To: michael-franzese@gmx.com
> > > > Cc: "help bash" <help-bash@gnu.org>
> > > > Subject: Re: Using Associative Arrays declared in functions
> > > >
> > > > try -g for declare to have it outside function available
> > > >
> > > > On Tue, Apr 13, 2021, 18:07 <michael-franzese@gmx.com> wrote:
> > > >
> > > > >  Am trying to ran some tests on some bash code.
> > > > >
> > > > >  Here is how I run my test
> > > > >
> > > > >  cd fractr-test
> > > > >  ./colr-test.sh
> > > > >
> > > > >  and this is what I get
> > > > >
> > > > >  termi-colr-wheel: * 79
> > > > >  colr-test: ***
> > > > >  Here is colr-fractr.sh
> > > > >  colr-test: ***
> > > > >  scout-terminfo-colours: **
> > > > >
> > > > >  For some reason I do still do not understand, I do not get the
> number
> > > 79
> > > > >  next to the double and triple stars.
> > > > >
> > > > >  Here is the code
> > > > >
> > > > >  ./colr-tools.sh
> > > > >  termi-colr-wheel ()
> > > > >    { declare -rA tis=([cols]="$(tput cols)")
> > > > >      echo "* ${tis[cols]} }
> > > > >
> > > > >  ./fractr-test/colr-fractr.sh
> > > > >  scout-terminfo-colours {echo "** ${tis[cols]}"}
> > > > >
> > > > >  ./fractr-test/colr-test.sh
> > > > >  tools_path=$(readlink -f "$0")
> > > > >  tools_path="${tools_path%/*}"
> > > > >  tools_path="${tools_path%/*}"
> > > > >
> > > > >  source ${tools_path}/colr-tools.sh
> > > > >
> > > > >  termi-colr-wheel
> > > > >  echo "colr-test: *** ${tis[cols]}"
> > > > >
> > > > >  source ./colr-fractr.sh
> > > > >  echo "colr-test: *** ${tis[cols]}"
> > > > >  scout-terminfo-colours
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
>


reply via email to

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