Naming variables

A variable name in bash must begin with a letter or an underscore, and can be followed by any letter or number, or more underscores.

These variables names are all legal:

  • myvar
  • MYVAR
  • Myvar
  • mYVAR
  • _myvar
  • my_var
  • myvar_
  • my012

These variable names are not allowed:

  • 1myvar
  • my-var
  • my.var
  • my:var

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.