Is it possible to set an environment variable name containing a period in BASH?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it possible to set an environment variable name containing a period in BASH?
I want to export several environment variables to a subprocess. As a result of circumstances outside my control, the names of the variables contain periods. In other words, I want to do something like this
> export foo.bar=123
bash: export: `foo.bar=123': not a valid identifier
I've tried using quotes and backslashes. Is it just impossible to do this?
I want to export several environment variables to a subprocess. As a result of circumstances outside my control, the names of the variables contain periods. In other words, I want to do something like this
> export foo.bar=123
bash: export: `foo.bar=123': not a valid identifier
I've tried using quotes and backslashes. Is it just impossible to do this?
Thanks
Yes. It's impossible.
Quote:
Originally Posted by bash man page
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.
I am curious as to why would it matter how an external process names the variables... You can name them internally as you wish. In any case you will be passing the variables to the bash script either as positional arguments or through a file, so... can you elaborate on why do you think you need to use a dot in the identifiers?
I want to pass the variables to an external process launched from BASH. Is there any way to do this, other than using export?
Cheers.
Quote:
Originally Posted by i92guboj
Yes. It's impossible.
I am curious as to why would it matter how an external process names the variables... You can name them internally as you wish. In any case you will be passing the variables to the bash script either as positional arguments or through a file, so... can you elaborate on why do you think you need to use a dot in the identifiers?
The external process wants to receive the values as environment variables of the form foo.bar=123. I have no control over this.
I am just trying to find a way to invoke the external process from BASH. Maybe there is some other way to do it -- Perl perhaps?
Cheers,
It doesn't matter if you use perl or a compiler designed in the NASA. Bash just doesn't allow dots in the names of identifiers, so, if the program is truly reading variables from your shell environment using getenv() or a similar function and it expect them to hold dots in the name of the identifier, then the program is just plain wrong from the root and should be changed. The other alternative is to patch bash in all your machines, and maintain it yourself. Not a pleasant one.
No shell that I know of (including bash, the plain posix bourne shell -sh-, and all the csh variants) will allow that. I don't know anything about ksh though, so I won't speak about it.
Are there any instructions that we can take at a look at or something? I really can't believe that the program has been done in such way because no shell that I know of can define identifiers which contains dots. Only A-Z,a-z,0-9 and _ are allowed, and the first character can't be a cypher.
No shell that I know of (including bash, the plain posix bourne shell -sh-, and all the csh variants) will allow that. I don't know anything about ksh though, so I won't speak about it.
I keep bumping into this post from google.
Actually, csh and tcsh support dots in their variable names.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.