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

87 views      
 

Messages in this Thread

 
93,933 Postings in 11,850 Threads, 347 registered users, 9 users online (2 registered, 7 guests)
Index | Admin contact |   Forum Time: Dec 10, 2018 - 12:13 pm EST  |  Hits:26,925,646  (2,114 Today )
RSS Feed