Create environment variable with dot in current environment

I know that you can create environment variables using the command env

.

For example:

env A.B=D bash

      

The problem is that the env command requires a command to create a new subprocess.

+3


source to share


2 answers


Bash does not allow environment variables with non-alphanumeric character names (except _). While the environment may contain a string such as A.B=D

, there is no need for the shell to be able to use it and bash cannot. Other shells can be more flexible.



Utilities using oddly named environment variables are discouraged, but some may exist. You will need to use env

to create such an environment variable. You can avoid the sub-process with help exec env bash

, but that won't help you significantly reduce your time or resources.

+6


source


rici has the correct answer. To demonstrate the difference required to access such environment entries, bash requires you to parse the environment as text:



$ env A.B=C perl -E 'say $ENV{"A.B"}'
C
$ env A.B=C bash -c 'val=$(env | grep -oP "^A\.B=\K.*"); echo "$val"'
C

      

+4


source







All Articles