Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export dot separated environment variables

Tags:

bash

unix

macos

Execution of

user@EWD-MacBook-Pro:~$ export property.name=property.value

Gives me

-bash: export: `property.name=property.value': not a valid identifier

Is it possible to have system properties with dot inside? If so how do that?

like image 761
Petro Semeniuk Avatar asked Feb 22 '13 03:02

Petro Semeniuk


People also ask

How do I export environment variables?

To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").

Can env variables have dot?

yml provides only one way for environment variables - as dict. So and we can't use dots in names as in the example above.

How do I print a list of the environmental variables?

Using the env Command env is another shell command we can use to print a list of environment variables and their values. Similarly, we can use the env command to launch the correct interpreter in shell scripts.

How do I separate environment variables?

Windows. You can create or change environment variables in the Environment Variables dialog box. If you are adding to the PATH environment variable or any environment variable that takes multiple values, you should separate each value with a semicolon (;).


1 Answers

I spent better part of this afternoon trying to figure out how to access some property set by Jenkins (to pass a job parameters jenkins uses property format with a dot) - this was a good hint from Adrian and yes it works for reading properties in the script too. I was at a loss as to what to do but then I tried:

var=`perl -e 'print $ENV{"property.name"};print "\n";'`

This worked quite well actually. But of course that works in a shell that was started with the property set in the environment already i.e. in Adrian's example this could work in a script started from bash instance invoked in perl example he provided. It would not if this perl sniplet was put in the same shell only directly after his perl example.

At least I learnt something this afternoon so not all this time is a waste.

like image 141
umghhh Avatar answered Nov 15 '22 20:11

umghhh