You're right about the spaces. In some cases, batch files/windows commands do take notice of any spaces between = and variables/strings. The trick is to be consistent with the number of spaces you use.
You should only need to use the second % character if you are referring to environment variables. This is true at the command line and in batch files. For example:
[tt]set mytext=Hello
echo %mytext%[/tt]
However %0, %1, %2 etc refer to the command line parameters which were passed to the script (%0 is the name of the script itself, %1 is the first parameter, etc). These do not need the second % character.
Similarly, if you define a temporary variable (say [tt]i[/tt]) using the [tt]for[/tt] command you can just refer to it by [tt]%i[/tt] at the command prompt or [tt]%%i[/tt] in a batch file. Don't ask me why it needs to be [tt]%%i[/tt] in a batch file, it just does.
Finally, beware of comparing a variable to a string if the variable might be empty. For example if your script contains this line
[tt]if %1==x echo Parameter was x[/tt]
then it will error if you run the script without a command line parameter (because %1 returns nothing, which == doesn't like). Instead, it's always safer to use the version with quotes:
[tt]if "%1"=="x" echo Parameter was x[/tt]
Right, I know I've tried to teach a bunch of you how to suck eggs there, but if it's of some help to at least one person I won't consider it a waste of my typing and your reading.
