help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dot in variable name


From: Greg Wooledge
Subject: Re: dot in variable name
Date: Thu, 14 May 2020 13:02:31 -0400
User-agent: Mutt/1.10.1 (2018-07-13)

On Thu, May 14, 2020 at 09:03:57AM -0700, Eric Peterson via wrote:
> I remember reading about variable names containing dots (i.e.  tax.amount).  
> Some sort of namespace of variables. 
> 
> $ declare tax.amount=0
> -bash: declare: `tax.amount=0': not a valid identifier

Shell variable names are not allowed to contain dots.

The definition is in the man page under PARAMETERS, which refers to
something called a "name".  The "name" is defined in DEFINITIONS:

       name   A word consisting only of  alphanumeric  characters  and  under‐
              scores,  and beginning with an alphabetic character or an under‐
              score.  Also referred to as an identifier.

That's what you're allowed to use as a shell variable name.

Now, there are *other* things that have names that may include dots.
For example, functions.  Or environment variables.  However, there is
a tight coupling between environment variables and shell variables in
shells.  Environment variable names that are NOT valid shell variable
names are generally stripped out of the environment by the shell when
it starts up, and cannot be exported into the environment with the
shell's "export" or "declare -x" commands.

To set an environment variable like this, you would need an external
tool, like env(1).

unicorn:~$ env foo.bar=baz
[...]
_=/usr/bin/env
foo.bar=baz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]