Skip navigation

Windows shell scripting

fantastic

The %stuff%

There are several items that you can use that looks like %this%.

  • %PATH%
  • %APPDATA%
  • %DATE%
  • %TIME%

basically, these %this% is how you access any of the environment variables defined on your system. Right click My Computer > Properties > Advanced > Environment Variables

Those are all the environment variables on your system.

At CMD:

C:\> echo %APPDATA%

HKLM local machine variables (bottom half) supercede current user variables (top half). Well, if you have a PATH variable defined as both HKLM and HKCU then if you echo %PATH% it gives you the HKLM machine variable; CONTENATE HKCU variable

Substring: %VAR:offset,len%

e.g.

echo %DATE:~1,2%    REM If its Dec, gives ec.  Starting at position 1, get 2 chars
echo %DATE:~1%      REM Goes from position 1 to end of string.  ec 27 08

Above example not that useful, but at least its clear how to work it

Getting random user input.

Try putting this into test.bat, then running it:

set /P MyAnswer=Tell me something: 

echo You said: "%MyAnswer%"

pause

Thanks to this guy again for that neat tip!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: