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


Groups > gnu.bash.bug > #15851 > unrolled thread

Re: Preventing Bash Variable Confusion

Started bykonsolebox <konsolebox@gmail.com>
First post2020-01-30 11:37 +0800
Last post2020-01-30 11:37 +0800
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#15851 — Re: Preventing Bash Variable Confusion

Fromkonsolebox <konsolebox@gmail.com>
Date2020-01-30 11:37 +0800
SubjectRe: Preventing Bash Variable Confusion
Message-ID<mailman.88.1580355467.2384.bug-bash@gnu.org>
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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web