Most online batch scripts come with a lot of quote issues.
Examples and Solutions
if %var%==abc echo Test
This code works – when the content of
%var% does not contains space or other special characters. Now let’s assume
%var% contains 1 whitespace. Now
if ==abc echo Test
This would cause a failure because
cmd.exe doesn’t understand this syntax.
if "%var%"=="abc" echo Test
cmd.exe sees the entire
%var%(including space and special characters) as only one normal string. Yet this is not the safest comparison method. The safest one uses
cd C:\User\Spaced Name\Spaced FileName.txt
cd would only change directory to
cd only accepts one path argument.
Simply by adding quotes around the path, the issue would be solved.
cd "C:\User\Spaced Name\Spaced FileName.txt"
There are also a few examples that work better using quotes, like the
set /a statement, etc. But, when one works on strings that contain spaces or special characters, it is usually much safe to use quotes.