Correct Bash and shell script variable capitalization

前端 未结 7 2017
太阳男子
太阳男子 2020-11-21 22:54

I run across many shell scripts with variables in all caps, and I\'ve always thought that there is a severe misunderstanding with that. My understanding is that, by convent

7条回答
  •  一整个雨季
    2020-11-21 23:23

    By convention, environment variables (PAGER, EDITOR, ...) and internal shell variables (SHELL, BASH_VERSION, ...) are capitalized. All other variable names should be lower case.

    Remember that variable names are case-sensitive; this convention avoids accidentally overriding environmental and internal variables.

    Keeping to this convention, you can rest assured that you don't need to know every environment variable used by UNIX tools or shells in order to avoid overwriting them. If it's your variable, lowercase it. If you export it, uppercase it.

提交回复
热议问题