bug-bash
[Top][All Lists]
Advanced

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

Preventing Bash Variable Confusion


From: Roger
Subject: Preventing Bash Variable Confusion
Date: Tue, 28 Jan 2020 16:02:25 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

I've used Bash for quite some time now and have heard lots about how variables 
should be named or styled.

1) Bash internal reserved words cannot be used a variables.  (OK. All of us who 
have programmed code get this and of course abide whole heartedly, else we fail 
quickly!)

2) Operating System (Bash or other) reserved variables are all defined as 
capitol letters, and all capitol letter variables should be avoided within Bash 
scripts.  (I've heard of this, however, I enjoy defining my variables in all 
capitol letters due to the increased readability of the script ... or in 
essence, all capitol letters readily distinguishes variables from other Bash 
words and operators.)

Some say variables should be prefixed (or suffixed) to further distinguish Bash 
variables from possible collisions with operating system Bash or other related 
variables.

I've thought about using "_VARIABLE" and have seen similar, but also requires 
an extra odd stressed finger combination prior to typing all capitol letters.  
Typing all capitol letters can be stressful, but the task improves readability 
in my point of view that the time and effort are well worth the effort, until I 
get to the additional underscore.

When and if I program in C, I tend to use all lower case style, my_variable.

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...

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

Attachment: signature.asc
Description: Digital signature


reply via email to

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