Reputation: 14926
I'm utterly confused by this one-liner from here, that pretty prints the %PATH%
variable.
ECHO.%PATH:;= & ECHO.%
Could you break this one-liner up, and explain what each part means?
For example,
%PATH%
split on semicolons?PATH
variable is normally referred to as %PATH%
. What's the syntax used here?ECHO.%
and :;=
mean?I'd also appreciate it if you could point to any resources that explain the syntax.
Upvotes: 2
Views: 122
Reputation: 14926
An example (underscore denotes space)
Say %PATH%
is a;b;c
The expression %PATH:;=_&_ECHO.%
replaces each ;
with _&_ECHO.
(see answer by @npocmaka)
This gives a_&_ECHO.b_&_ECHO.c
Since %PATH%
does not begin with a semicolon, we must prepend ECHO.
to the above expression to make sure the first directory a
is printed. This gives
ECHO.%PATH:;=_&_ECHO.%
which expands to ECHO.a_&_ECHO.b_&_ECHO.c
ECHO.
why the dot?
Say %PATH%
is a;b;;c
If we use ECHO_
we will get
a
b
ECHO is on.
c
If we use ECHO.
we will get
a
b
c
From this discussion,
ECHO.
is used to get the ECHO statement to output a blank line. In accordance with its design, the ECHO issued blank or with just white space after the command text, outputs the current 'echo' status, that is ON or OFF.
Upvotes: 2
Reputation: 57272
first check this: https://ss64.com/nt/syntax-replace.html
the semicolon means that a substring in the variable will be replaced.First is the old substring then equal sign,then is the new one.
In this case every semicolon is replaced with the command ECHO.
which prints a new line.
The ampersand is used to execute more command on a single line.
As there is no delayed expansion the expansion of the variable will execute also the echo commands.
Upvotes: 4