How do I set an environmental variable with a dot?

I couldn't find a way to set an environmental variable with dot (.).

For example:

export mule.home=/Users/chandra/mule/
export {mule.home}=/Users/chandra/mule/
export $mule.home=/Users/chandra/mule/

all throw an error indicating it's not a valid identifier, like:

-bash: export: `.home=/Users': not a valid identifier

Setting mule_home works but not mule.home. Any ideas, suggestions?

2

1 Answer

That is because a name with a dot—and you can believe your shell here—is not a valid identifier. From man bash:

name A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier.

The dot is not an alphanumeric character and it's not an underscore either. You can create something like:

env mule.home=/Users/chandra/mule/

But you won't really be able to read this, as far as I know. Also, bash should prevent you from even creating those identifiers in the first place.


My suggestion would be to create the environment variable with an underscore instead, and possibly use UPPERCASE words, as it's common practice.

Or use another shell that supports dots in environment variables, for example csh and tcsh.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like