To All:
People who often write batch scripts must be very familiar with the sentence pattern "if string1==string2 command arguments". Because string1/2 can refer to variables, there may be empty values, so it is necessary to prevent syntax errors when if statements occur when string1/2 is empty.
The most commonly used method is to prevent empty characters. Initially, there were many choices for preventing empty characters, such as:
if #%1==# goto end
if == goto end
if %1!==! goto end
However, with the in-depth use of batch scripts, all the above methods of preventing empty characters have been eliminated. The key reason is that they cannot avoid syntax errors when string1/2 contains spaces. For example, the following statement is a syntax error:
if == goto end
At this time, the paired double quotes seem to be the only choice:
if "%1"=="my project" goto end
However, it is still not the best choice. If both quotes and spaces appear in string1/2, the syntax errors we dislike will appear again:
if "%1"=="my project:"code for oop"" goto oop
What should we do next? Don't ask me, I don't know the answer!
[ Last edited by willsort on 2005-7-29 at 22:23 ]
People who often write batch scripts must be very familiar with the sentence pattern "if string1==string2 command arguments". Because string1/2 can refer to variables, there may be empty values, so it is necessary to prevent syntax errors when if statements occur when string1/2 is empty.
The most commonly used method is to prevent empty characters. Initially, there were many choices for preventing empty characters, such as:
if #%1==# goto end
if == goto end
if %1!==! goto end
However, with the in-depth use of batch scripts, all the above methods of preventing empty characters have been eliminated. The key reason is that they cannot avoid syntax errors when string1/2 contains spaces. For example, the following statement is a syntax error:
if == goto end
At this time, the paired double quotes seem to be the only choice:
if "%1"=="my project" goto end
However, it is still not the best choice. If both quotes and spaces appear in string1/2, the syntax errors we dislike will appear again:
if "%1"=="my project:"code for oop"" goto oop
What should we do next? Don't ask me, I don't know the answer!
[ Last edited by willsort on 2005-7-29 at 22:23 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!

