2

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,

  • How is %PATH% split on semicolons?
  • The PATH variable is normally referred to as %PATH%. What's the syntax used here?
  • What doECHO.% and :;= mean?
  • Where is the "for each line, echo it out" logic?

I'd also appreciate it if you could point to any resources that explain the syntax.

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80

2 Answers2

4

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.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
2

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.

kgf3JfUtW
  • 13,702
  • 10
  • 57
  • 80