lundi 13 février 2017

What's the meaning of these lines of code from a batch file?

Vote count: 0

I'm trying to explain a batch file I've written for work and I'm having a hard time explaining this one section. To be clear, the section works as designed so this is not a question about how to write it; I just can't figure out what it's called and how to explain it to a coworker. In particular, I'm curious about the bit with the tilde. For instance, :~0,1 in my bit of code and :~0,3 and :~3,2. For the life of me, I cannot explain how they work. I think they expand the variable but that's only what can come up with from Googling.

This is the section from my script:

:_RebootQuestion
ECHO.
Set /p _Resp=Would you like to reboot now (Y/N)?
If /I "%_Resp:~0,1%"=="Y" shutdown -r -t 0 -f
If /I "%_Resp:~0,1%"=="N" exit
If /I NOT "%_Resp:~0,1%"=="N" (
    Echo Y or N please. &GoTo _RebootQuestion
    )

This is an example I've seen out on the web:

set test=12345 
echo %test:~0,3% 
echo %test:~3,2%

asked 28 secs ago

Let's block ads! (Why?)



What's the meaning of these lines of code from a batch file?

Aucun commentaire:

Enregistrer un commentaire