What are the rules for assigning variables in Bash?
BeginnerConceptVariables, quoting and expansions
Answer
No spaces around =. name=value assigns; name = value runs a command named name with arguments = and value. Names are letters, digits and underscores, not starting with a digit. The right side does not undergo word splitting or globbing, but quoting it is still a good habit.
APP_DIR=/srv/app
release="$(date +%Y%m%d%H%M%S)"
msg="deploy of ${release} started"
Use lowercase for script-local variables and UPPERCASE for exported/environment ones, so you never clobber PATH, HOME or USER by accident.
More on Variables, quoting and expansions
What is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?IntermediateHow do you do search-and-replace, substrings, length and case conversion without external tools?Intermediate