8

Can anyone explain what is :~1% in the below statement in a batch file? I assigned the value of %variable to servername and tried echo %variable. I get the same server name as output. Can anyone explain how the statement below works?

set variable=%variable:~1% 

2 Answers 2

7

this is notation for subs string expansion , look at this out put form command line you will understand.

C:\>set temp=stackoverflow.com C:\>echo %temp% stackoverflow.com C:\>echo %temp:~5% overflow.com C:\>echo %temp:~5,8% overflow C:\> 

if you have not understood , here is syntax (in my words)

set variable=%variable:~startingCharector [,OptionalLenghtOfCharctors]% 

where

OptionalLenghtOfCharctors by default it takes remaining characters of string.

Sign up to request clarification or add additional context in comments.

2 Comments

Basically its a substring and split. Now able to understand the script. Thanks Baljeetsingh.
@user3437439 glad to help you ! , you can help stackoverflow back by marking the correct answer as green tick.
5

It's a syntax for substrings from the variable contents, in this case it removes the first character.

See set /? for help

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.