Silvainius01
Silvainius01

Reputation: 23

Batch "SET" command

I keep seeing "set y=%y:~0,-2%" or some visual equivalent to it in code, but I have no idea what it's called, what it does, or how it's syntax works; I haven't been able to find an explanation, just more uses of it. Can some one explain?

Upvotes: 1

Views: 13993

Answers (2)

Jayjar291
Jayjar291

Reputation: 22

Set is used to set variables eg.: set /p A= will ask the user for input.

in cmd type set /?

Upvotes: 0

paulsm4
paulsm4

Reputation: 121599

  1. "Set" sets the value of a Windows variable.

    EX: set myvar=abc <= assigns the string "abc" to variable "%myvar"

  2. "%" deferences the current value of a Windows Variable.

    EX: echo %myvar% <= prints "abc"

  3. The %y:~0,-2 syntax extracts a substring from the current value of the variable
    <= extracts last 2 characters from Windows variable "%y"

Here are some useful links that might help :

Upvotes: 1

Related Questions