LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2009, 06:35 PM   #1
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Variable gNames...


Hello All,

This is just a question about "personal preference"...

Why do people use UPPERCASE variable names in shell scripting? From what I've been taught; UPPERCASE variables are reserved for environmental variables.

So then why use UPPERCASE variables

Example:
Code:
#!/bin/bash
VAR=one
#
echo $VAR
#
^ Why use the UPPERCASE?

-C

P.S. FWIW The UPPERCASE variable thing is a pet peeve of mine...and I just want to know why all you guys are doing it "wrong"
 
Old 01-02-2009, 07:52 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I've never heard of any rule that says caps must be reserved for environmental variables. To me a variable is a variable, whatever its purpose.

I generally use uppercase for my variables simply to make it clear that they are variables. It sets them apart from commands, comments, and other code, and helps to make everything more readable.

Other people may do it differently, perhaps by using some kind of standard prefix or something, but for the same reason: to make the variable names stand out from the rest of the code.

In the advice I've read about coding style, they usually say the more important thing is to choose a pattern that works well and use it consistently.

But then again, I'm just an amateur hacking away as best I can, so what do I know.
 
Old 01-04-2009, 07:59 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Yeah, consistency is probably the most important thing, IF you are on your own. Otherwise agree a std with your co-workers and stick to it (consistency again..).

The UPPERCASE thing is prob related to:
1. ex-BASIC programmers, and shell is similar in some ways.
2. MSDOS: its not case sensitive, so uppercase is common

In C, usually vars are lowercase, CONSTANTS (inc #defines) are set UPPER for clarity.

Personally I can't stand CamelCase. I find it hard to read compared to lower_with_underscores and also its hard (for me) to type
 
Old 01-05-2009, 11:14 AM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979

Original Poster
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by chrism01 View Post
Yeah, consistency is probably the most important thing, IF you are on your own. Otherwise agree a std with your co-workers and stick to it (consistency again..).

The UPPERCASE thing is prob related to:
1. ex-BASIC programmers, and shell is similar in some ways.
2. MSDOS: its not case sensitive, so uppercase is common

In C, usually vars are lowercase, CONSTANTS (inc #defines) are set UPPER for clarity.

Personally I can't stand CamelCase. I find it hard to read compared to lower_with_underscores and also its hard (for me) to type
I can agree to that...consistency is important.

I guess it's more how you are taught...I always got a "ruler to the hand" when I would use uppercase variables

-C
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find variable name by variable content using a subshell UltramaticOrange Programming 3 11-17-2008 03:51 PM
Sed search for variable and delete entire line, but variable contains forward /'s Passions Programming 2 11-10-2008 03:44 PM
function showing a list of variable and value: (dynamic variable name) budhax Linux - Newbie 1 09-19-2008 07:05 PM
Help: removing a variable substring from a string variable in sh script gnparsons Programming 2 06-04-2008 05:21 PM
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 11:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration