Reputation: 507
Are there any rules for unix/linux shell variable naming?
For example, like the common rules for Java variable naming.
Upvotes: 2
Views: 2576
Reputation: 289725
You have to be very careful not to use any UNIX command as a variable. It will mess the code and produce unexpected results. Also, keep in mind the reserved words (if
, else
, elif
, do
, done
...) and that uppercase variables are reserved for system use.
From Rules for Naming variable name:
Variable name must begin with
alphanumericalpha character or underscore character (_), followed by one or more alphanumeric or underscore characters. Valid shell variable examples
Or as seen in The Open Group Base Specifications Issue 7:
In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.
Upvotes: 3