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


Groups > gnu.bash.bug > #15852

Re: Preventing Bash Variable Confusion

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Roger <rogerx.oss@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: Preventing Bash Variable Confusion
Date Thu, 30 Jan 2020 01:40:18 -0500
Lines 40
Approved bug-bash@gnu.org
Message-ID <mailman.92.1580366438.2384.bug-bash@gnu.org> (permalink)
References <20200128210225.GC12574@localhost4.local> <CAJnmqwbr6EVJOZn6SLdByAgZAoFN60ahCp3m2HJyJ6VS=hwEvg@mail.gmail.com> <20200130064018.GA23692@localhost4.local>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1580366439 8383 209.51.188.17 (30 Jan 2020 06:40:39 GMT)
X-Complaints-To action@cs.stanford.edu
To konsolebox <konsolebox@gmail.com>, bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Blcp1N0Ru806d8Z0MPI5stk/qzkIu3U4TGXrZ3+UyFc=; b=buSTEWybUck4nvnGGio6ScGfYlDyuqyu2BGxLagtleLDuSTLzKOwnkL4vCt0w5l6NZ 07oRf/2/q8IeaT14uTIAADdfbnU5340FIo2wKQyvuh6rQlmFVcRfZxnT7SrF08GYuOB+ HDpQXVfgQSAc3DruW4U9KCTzmwUZQU2mcPStZkdG1vjwRJqz1of4Xmam/O+fnB8DN3Mj r4rHVkujTzK7AUsRK4FMT8hPu61UOFyuEEGaCQck+Bya5iQNSMdofSo19J5ptnsC4S9I oNF7Hv0lla7ksL50MwhC2HMJS6xH4SusJB3+9Zl88fynLQsBpu4Y8gJfVoGZkbY0qks7 g/DA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Blcp1N0Ru806d8Z0MPI5stk/qzkIu3U4TGXrZ3+UyFc=; b=HRcF++mHk9R92LyMA3+47I7qUIHD2pIUo0qPDf+i2m9ECxFxLUe8Zc4R2kubMgLPQ5 AtLaUK1rcB60DAcpyCk+V1ET5fpS9t+d8gfhSENyPEPP3g2Lfn5zcAJC7U63nYlpfaIF moqCEusmYS9kasA9l42sbA4cOCWUAFI0lXWr6R/heA0yIAy4j4dMWbebckvcT9gBDePl 7+J/C00GY8nb27QpHnAlgFBQajByIbgHy5I7pJMUDph34r6rxkl9IH9C2aG9zH22JrM4 vgxMW/Rn63HnSmnbTyDfBUQ3hgqv1CNsao3w7D7GuSAElKZYUuBZbl+GcNV8b3FywT84 0L5Q==
X-Gm-Message-State APjAAAVST0QV4Uahn4fJZx7VCQu8RR7quPV20SYe65ipxFeapJ8nT7kP mGUyVFXOBKzRcFrLldf8eo0=
X-Google-Smtp-Source APXvYqy1ILDzmbUQtGXms5fYpmhQD7wQ5FneiSydgAIrm5kyl6lKH1mwMctbsEftCv8xYGLLOqFDug==
X-Received by 2002:a05:6214:13ef:: with SMTP id ch15mr3096791qvb.183.1580366419612; Wed, 29 Jan 2020 22:40:19 -0800 (PST)
Content-Disposition inline
In-Reply-To <CAJnmqwbr6EVJOZn6SLdByAgZAoFN60ahCp3m2HJyJ6VS=hwEvg@mail.gmail.com>
X-PGP-Key http://rogerx.sdf.org/about/armor-F515AC1F231FFC4EF0BCDE7606CEA0ECE2887C75-20170104.asc
User-Agent Mutt/1.10.1 (2018-07-13)
X-detected-operating-system by eggs.gnu.org: Genre and OS details not recognized.
X-Received-From 2607:f8b0:4864:20::f2c
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <20200130064018.GA23692@localhost4.local>
X-Mailman-Original-References <20200128210225.GC12574@localhost4.local> <CAJnmqwbr6EVJOZn6SLdByAgZAoFN60ahCp3m2HJyJ6VS=hwEvg@mail.gmail.com>
Xref csiph.com gnu.bash.bug:15852

Show key headers only | View raw


> On Thu, Jan 30, 2020 at 11:37:26AM +0800, konsolebox wrote:
>
>   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

I've thought about this, yes I can use that style.  However...

1) Using an underslash on all capitol variable names just looks ugly in my 
opinion.  Or more to the point, the style seems to stray away from main stream 
styles.

2) Prefixing variable names with the name of the script (or other lengthy 
prefix) requires more characters I could be using for describing my variable or 
function.  (If I were writing unreadable code, I probably would not mind.)


I've decided to comply with Google's Style guidelines, even though they do not 
pay me a paycheck, but they do give me lots of free stuff.  Shrugs, besides, 
the more my Bash scripting looks like C, the easier it is to read.

The can push me away from defining my variables in all capitol letters.  They 
can even push me to code in C and Assembly, but just don't push me to script in 
Python.


-- 
Roger
http://rogerx.sdf.org/

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


Thread

Re: Preventing Bash Variable Confusion Roger <rogerx.oss@gmail.com> - 2020-01-30 01:40 -0500

csiph-web