[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
- Re: Preventing Bash Variable Confusion, (continued)
- Re: Preventing Bash Variable Confusion, Robert Elz, 2020/01/29
- Re: Preventing Bash Variable Confusion, Greg Wooledge, 2020/01/29
- Re: Preventing Bash Variable Confusion, Roger, 2020/01/29
- Re: Preventing Bash Variable Confusion, Chet Ramey, 2020/01/29
- Re: Preventing Bash Variable Confusion, Roger, 2020/01/29
- Re: Preventing Bash Variable Confusion, Chris F.A. Johnson, 2020/01/30
- Re: Preventing Bash Variable Confusion, Robert Elz, 2020/01/30
Re: Preventing Bash Variable Confusion,
konsolebox <=
Re: Preventing Bash Variable Confusion, Greg Wooledge, 2020/01/30