help-bash
[Top][All Lists]
Advanced

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

Re: Avoiding setting same variables multiple times


From: pauline-galea
Subject: Re: Avoiding setting same variables multiple times
Date: Wed, 7 Apr 2021 20:27:13 +0200

Found out about "type -t".  Would this be robust enough?
See code below.

You suggest not to hard-code the ANSI escape sequences.
Does the comment suggest that I can construct the ANSI escape
sequence?


function section-spec()
  {
    ansi-colr-codes
    test=`type -t ansi-colr-codes`
    test=`type -t ansi-colr`
    echo "test $test"
    secn_Nc="%s\n"
    secn_Bk="${bBk}%s${nc}\n"
    secn_Rd="${bRd}%s${nc}\n"
    secn_Gn="${bGn}%s${nc}\n"
    secn_Yl="${bYl}%s${nc}\n"
    secn_Bl="${bBl}%s${nc}\n"
    secn_Mg="${bMg}%s${nc}\n"
    secn_Cy="${bCy}%s${nc}\n"
    secn_Wh="${bWh}%s${nc}\n"
  }



> Sent: Thursday, April 08, 2021 at 6:17 AM
> From: "Greg Wooledge" <greg@wooledge.org>
> To: help-bash@gnu.org
> Subject: Re: Avoiding setting same variables multiple times
>
> On Wed, Apr 07, 2021 at 07:57:30PM +0200, pauline-galea@gmx.com wrote:
> > Is there any neat way to set the variables but not end
> > up setting them multiple times?
>
> Call the init function once, explicitly, at the beginning of the
> script.
>
> A compromise approach would be to check one of the variables, and call
> the init function only if it's unset/empty.
>
> Also, while you're at it, consider not hard-coding the ANSI escape
> sequences.
>
>



reply via email to

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