bug-bash
[Top][All Lists]
Advanced

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

Re: Preventing Bash Variable Confusion


From: konsolebox
Subject: Re: Preventing Bash Variable Confusion
Date: Thu, 30 Jan 2020 11:37:26 +0800

On Wed, Jan 29, 2020, 05:02 Roger <rogerx.oss@gmail.com> wrote:

> Anybody have any further insight concerning variable naming styles aside
> from
> what's already written within the documentation?
>
> I could do something like MY_VARIABLE, but then prefixing with "MY_" eats
> up
> three more chars I could have used for describing my variable better.
> Shrugs...


Here's my take.

You can still use all caps on global variables just mind the internal
variables. You can have it prefixed by an underscore if you worry about
conflicts.  You can also have it prefixed with the script's name in all
caps.  It's best to have the variables initialized at the beginning if the
script so it's explicit that you intend to use the variables as global
variables of the script.

And then you use lowercase on local.  Use an underscore or two-underscores
prefix on indirect variables and never reference an indirect variable with
another.  This includes passing the indirect variable for reference to
another function.

--
konsolebox


reply via email to

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