0

The question in its simplest form:

Which is a better practice, to use lowercase or uppercase letters when creating user defined variables? Or does it really matter?

The story behind this:

My Linux teacher at my university tried to convince us to always use uppercase letters when creating user defined variables. From my experience so far, I've understood that it's the opposite. User defined variables should be written with lowercase letters.

I have some sources to support my understanding

A quote from Linux Command Line and Shell Scripting BIBLE, Third Edition (Blum & Bresnahan 2015, p. 139)

The standard bash shell convention is for all environment variables to use uppercase letters. If you are creating a local variable for yourself and your own shell scripts, use lowercase letters. Variables are case sensitive. By keeping your user-defined local variables lowercase, you avoi the potential disaster of redefining a system environment variable.

I also found an answer on Unix & Linux Stack Exchange

Since I disagreed with my teacher, I questioned him with the same sources. Only to hear that it's possible that there is a mistake in the book. I'm just little confused now.

I appreciate if somebody with a lot of experience in bash shell could provide an answer with "deeper" explanation.

Thanks.

  • 1
    Real life example of problems with uppercase: askubuntu.com/a/657105/158442 – muru Nov 30 '16 at 12:37
  • Generally the common practice is to use ALL_CAPITALS for exported variables; the practice for non-exported variables varies, but usually non-exported variables with short names (like $i, $f, $dir, $file, $x) are lowercase. See the Shell Style Guide. – AlexP Nov 30 '16 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.