ZTree.com  | ZEN  | About...  

 Index   Back

[Q] REM #ZTStart "" behavior changes or something else like a bug?   [Q]

By: Nick Williams     West Sussex, England (forum time +5 hrs)  
Date: Oct 06,2018 at 17:51
In Response to: [Q] REM #ZTStart "" behavior changes or something else like a bug? (Ryan)

> AA=
> REM #ZTStart ""
> REM #ZTSet VAR AAAAAA do not type 1 but just press enter to bypass=
> IF /I %VAR%==1 ECHO ddddd
> pause
>
>
> BB=
> REM #ZTStart ""
> REM #ZTSet VAR AAAAAA do not type 1 but just press enter to bypass=
> IF /I "%VAR%"=="1" ECHO ddddd
> pause
>
>
> why does AA= cause an error? while BB= works well.

Hi Ryan,

Your BB= example is the correct way to code this. The double-quotes are required because the %VAR% environment contains spaces.

When the command processor interprets the script, the %VAR% is expanded -- the spaces would make a nonsense of the IF /I statement without the double quotes to contain them.

It's good coding practice to ALWAYS use double quotes in IF statements -- even when you feel sure that your environment variables will never contain spaces or other argument separator characters (delimiters), e.g. comma, semicolon, equals, space, tab. Also, characters like the pipe symbol, ampersand and less-than and greater-than need to be within double quotes.

Hope this helps.


Kind regards
Nick

134 views      
 

Messages in this Thread

 
94,242 Postings in 11,887 Threads, 347 registered users, 11 users online (1 registered, 10 guests)
Index | Admin contact |   Forum Time: Apr 18, 2019 - 2:22 pm EDT  |  Hits:27,505,720  (1,650 Today )
RSS Feed