Pradip Shenolkar
Pradip Shenolkar

Reputation: 817

% in Windows environmental variables value

What does % mean in windows environmental variables ?

%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;

Especially the Path, TMP, TEMP variable values have this sign. There might be other variables also, but I came across only these three.

Do I need to bother about it while setting my own path variables ?

Upvotes: 2

Views: 233

Answers (2)

Harry Johnston
Harry Johnston

Reputation: 36348

Do I need to bother about it while setting my own path variables ?

Under normal circumstances, no, you don't. You would only do this if you wanted the effective value of PATH to depend on some other environment variable. Even then it is only a convenience, never a necessity.

As a real-world example of when it might be convenient, suppose you've written a program that automates updating the Java SDK to the latest version, so your users don't have to do it by hand. Updating the SDK moves it to a different location, so you probably want to add the new location of the SDK to the path, and remove the old one.

You could do that the hard way, by parsing PATH each time, locating the part that points to the old location and changing it appropriately. But that's a pain, and if you're doing this globally, the users don't have any choice over whether Java is in the path, even if they don't use it. So instead you might create a variable JAVA_PATH that points to the current SDK location. That way, it is easy to change, and individual users can choose whether or not to put %JAVA_PATH% in their own paths.

In Microsoft's case (the examples you noticed) the system root is never going to move, but by using a variable they could hard-code the default value of PATH rather than having to explicitly generate it during operating system installation.


PS: the environment variables referenced in PATH must all be system variables. Referencing a user variable will not work.

Upvotes: 2

JLRishe
JLRishe

Reputation: 101748

%VariableName% is the syntax for referencing an environment variable. The actual name is the part between the % symbols.

So your first line, when fully expanded, would evaluate to the value of the SystemRoot variable, followed by \system32;.

You'll need to use %...% if you want to make use of environment variables in the Windows shell, or if you want to define environment variables that reference other variables.

Upvotes: 1

Related Questions