Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does it mean batch set variable=%variable:~1%

Tags:

batch-file

cmd

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%
like image 694
intechops6 Avatar asked Mar 19 '14 12:03

intechops6


2 Answers

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.

like image 170
Baljeetsingh Avatar answered Oct 31 '22 21:10

Baljeetsingh


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

See set /? for help

like image 21
AjV Jsy Avatar answered Oct 31 '22 21:10

AjV Jsy