The Windows command processor (cmd.exe) supports environment variables like USERNAME
and USEPROFILE
. The value of these variable is always the same after they have been set. But if I execute echo %TIME%
I get a 'dynamic' value. So clearly there is an execution path for the environment variable syntax that can result in a dynamic value. (Unless the operating system actually updates the TIME
variable every second. But I don't think so, because TIME
is not listed when executing the set
command.)
So how do I set an environment variable that results in execution of a script or program when evaluated?
Background:
I want to add information to my command prompt, based on the current working directory. The Windows Command Processor uses whatever is in the PROMPT
environment variable as its prompt. If I can make an environment variable that is dynamic then I can probably achieve what I want.
cmd.exe
provides%TIME%
, it is most likely a special implementation. It is unlikely you would be able to replicate this without modifyingcmd.exe
.%CD%
is a relevant built-in example of a dynamic environment variable.__APPDIR__
. I would not be surprised if Windows can't be extended to support user-defined dynamic environment variables, but without asking here I would be less sure of that. Thanks