Following tips are useful while scripting in Windows
Everybody likes comments to there scripts. In win32 shell any line starting with :: is a comment
:: This is a comment
Conditional loops are favorites for all sysadmin in their daily tasks. For eg: one would use a for loop in bash to list a directory and do some stuff on the files and sub-folders in it. Like below,
for n in * ;do echo $n; done
This will display the contents of current working directory.
How will you do it in a windows shell ? Here it is,
Try this in a windows command prompt,
:: echo off will disable echoing the commands back to stdout @echo off
:: Here %V is a single letter replaceable variable FOR /F "tokens=*" %V IN ('dir /b .') DO echo %V
If you are putting the command in a batch script %V should be replaced with %%V.
Try out another interesting eg:
FOR /L %i IN (0 2 100) DO echo %i
Which will simply, echo all the numbers in between zero and 100 inclusive, incrementing by 2 each time.
Try ‘for /?’ for help page