I know that you can create environment variables with the command env
.
For example:
env A.B=D bash
The problem is for env a command is required thus creating a new subprocess.
It is not possible to set environment variables with dots in their name. If you try to set one in the UI, it just does not work without error message.
2.2 Set/Unset/Change an Environment Variable for the "Current" CMD Session. To set (or change) a environment variable, use command " set varname=value ". There shall be no spaces before and after the '=' sign. To unset an environment variable, use " set varname= ", i.e., set it to an empty string.
To make permanent changes to the environment variables for all new accounts, go to your /etc/skel files, such as . bashrc , and change the ones that are already there or enter the new ones. When you create new users, these /etc/skel files will be copied to the new user's home directory.
Bash does not allow environment variables with non-alphanumeric characters in their names (aside from _). While the environment may contain a line such as A.B=D
, there is no requirement that a shell be able to make use of it, and bash will not. Other shells may be more flexible.
Utilities which make use of oddly-named environment variables are discouraged, but some may exist. You will need to use env
to create such an environment variable. You could avoid the subprocess with exec env bash
but it won't save you much in the way of time or resources.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With