I spend some time working batch frameworks and I started to think more about presentation finally... How the scripts looks like etc.
This is going to be (extremely) short topic, about two or three posts, however I hope so I could save you some time.
First I decided to separate regular output with sections. Section should looks like <Section name>, after this there should be some tab and finally text of the script:
<Important warning>
Earth is going to explode soon
Starting with evacuation.
If you would like to have output like this, first problem you will run into will be "The syntax of the command is incorrect.". This is because "<" and ">" are acting as redirection characters. If you want to ignore their function and use them "as-is", you must specify escape character. This is "^" for batches. So instead of Echo <Important warning> you should use Echo ^<Important warning^>.
This is maybe useless with above example, however sometimes this is extremely important to understand when writing more complex scripts.
Consider following example: You want to retrieve some variable from file. File name is test.ini, variable name is TestParameter and you want to store value in variable TestValue.
You will probably create script which is similar to following:
For /f "usebackq delims== tokens=1,*" %%i IN (`Type test.ini`) Do If /i #%%i# EQU #TestParameter# Set TestValue=%%j
This syntax is correct - however if you are using biiiiiiiiiiiiiiig ini files (as I usually do ;)), your script will be quite slow. Wouldnt it be better to use something like
For /f "usebackq delims== tokens=1,*" %%i IN (`Type test.ini | Find /i TestParameter=`) Do If /i #%%i# EQU #TestParameter# Set TestValue=%%j
?
So you will do If/Set procedure only for matching lines (there will be most of the time only one)?
Problem is that if you run this line, interpreter will separate it to two parts:
For /f "usebackq delims== tokens=1,*" %%i IN (`Type test.ini | Find /i TestParameter=`) Do If /i #%%i# EQU #TestParameter# Set TestValue=%%j
So it will try to send first part through pipe to Find.com. Of course this wont work at all. However if you use escape character for pipe sign ("|"), it will work!
For /f "usebackq delims== tokens=1,*" %%i IN (`Type test.ini ^| Find /i TestParameter=`) Do If /i #%%i# EQU #TestParameter# Set TestValue=%%j