Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15851

Re: Preventing Bash Variable Confusion

From konsolebox <konsolebox@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Preventing Bash Variable Confusion
Date 2020-01-30 11:37 +0800
Message-ID <mailman.88.1580355467.2384.bug-bash@gnu.org> (permalink)
References <20200128210225.GC12574@localhost4.local> <CAJnmqwbr6EVJOZn6SLdByAgZAoFN60ahCp3m2HJyJ6VS=hwEvg@mail.gmail.com>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Preventing Bash Variable Confusion konsolebox <konsolebox@gmail.com> - 2020-01-30 11:37 +0800

csiph-web