Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Most languages have naming conventions for variables, the most common style I see in shell scripts is MY_VARIABLE=foo. Is this the convention or is it only for global variables? What about variables local to the script?

share|improve this question
The only one that I know of which everyone should follow is all uppercase names should be reserved for the shell. Don't use them to avoid accidentally clobbering something important like PATH or HOME or anything else the shell might reserve in the future. –  jw013 Jul 11 '12 at 20:53
Actually, all uppercase names are typically used for environment variables. Some variables (like PATH) are interpreted by the shell, while others (like LANGUAGE or PRINTER) may be interpreted by other programs, but there is nothing otherwise special about them. –  jlp Jul 11 '12 at 23:01
'environment variables' is indeed the proper name, I'll include it in my answer. –  jippie Jul 12 '12 at 6:45

1 Answer 1

up vote 19 down vote accepted

Variables that are introduced by the operating system or start up scripts etc. are usually all in CAPITALS, these are called 'envrironment variables'.

To prevent your own variables from conflicting with environment variables, it is a good practice to use lower case.

share|improve this answer
Pretty much what @jw013 says in his comment. –  jippie Jul 11 '12 at 20:55
lower_case underscore separated or camelCase? –  Garrett Hall Jul 11 '12 at 20:55
@GarrettHall That's entirely up to you. Once you pick one stick with it. Consistency is more important than the actual choice. –  jw013 Jul 11 '12 at 20:57
matter of taste? I personally like the C-style camelCase because it is shorter and doesn't use the ugly underscore. Taste, style, ... –  jippie Jul 11 '12 at 20:57
matter of taste? I personally like underscore separated, easier to read. –  janos Jul 12 '12 at 8:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.