Simply add another variable on a new line using set
as shown in your example. You will also want to remove the /K switch from the first line as execution will stop after that line.
set NEWVAR=SOMETHING
will create a new variable called NEWVAR
with the value SOMETHING
. If you wish to keep the same behavior and keep cmd
open with the /K switch just put it at the end.
example:
set PATH=%PATH%;C:\Folder;
set NEWVAR=SOMETHING
echo %NEWVAR%
Processes (including shells) only inherit variables from their parents. There is no way to change them from the outside thereafter.
Set "global variables" as early in the boot (for system processes) or shell invocation (for user processes) as possible, or resign yourself to setting them in multiple places.
This may seem like a pain, but the ability to change another processes environment would be a bug, and would introduce all kinds of nasty race conditions.
What are you trying to do that you want "global" environment variables? There may be way to work around your problem.
Workaround:: Write a minimal script in your favorite shell format that only sets the variable you want and put it in a globally accessible place:
/etc/loglocaltion.sh
:
export MY_LOG_DIR=/opt/share/mylog
export MY_DEFAULT_LOG_LEVEL=URGENT
and for everything that you want to use that configuration do one of
- launch it from shell which has
source
ed loglocation.sh in it's non-interactive login file (the one that gets read for all instances of the shell, i.e. .bash_profile
).
- write a minimal wrapper script which sources
loglocation.sh
before launching the real program. launchcorelogger.sh
:
CORELOGGER=/opt/sbin/mycorelogger
source /etc/loglocation.sh
exec $CORELOGGER
and have init
run the script.
Now edits to the loglocation script will effect all associated processing if your run them from a fresh shell in the first case or restart them using you systems dameon restarted (/etc/init.d/mycorelogger restart
or whatever).
Best Answer
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:
you are just setting it in the current process space.
According to this page you can use the
setx
command:setx
is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit