Question:
Began studying cmd
, environment variable reached PATH
– its meaning is clear, but that's what makes the design cycle, for example, this:
for %%i in ("%PATH:;=" "%") do (...something)
I don't understand what is i
initialized with? and how to understand in (...)
in this case?
Answer:
for %%i in (...)
interpreted in an obvious way – it is a loop over a set of values, but how a set of values is constructed in this case is much more interesting.
The entry "%PATH:;=" "%"
interpreted as follows.
Everything between the %
signs is a variable and its processing operators. Processing statements begin after the :
sign. Those. in this case, the variable name is PATH
, the processing operators are ;=" "
. Since our expression contains a space, it must all be enclosed in quotes.
The processing operator in this case is a substitution operator. The string to the left of the equal sign will be replaced with the string to the right. In other words, the construction
%VARIABLE:BEFORE=AFTER%
replaces all occurrences of BEFORE
in VARIABLE
AFTER
. In our case ;
– directory separator – will be replaced with a space, which the for
loop will interpret as a separator of elements.