hi
i am using below script which is not working
set res1='YES'
echo !res1!
if "!res1!" EQU "YES" echo "HI"
its not displaying HI , please help
string not working
Moderator: DosItHelp
Re: string not working
You compare "'YES'" with "YES". The first has an additional pair of single quotes as assigned using SET.
Steffen
Steffen
-
- Posts: 21
- Joined: 16 Aug 2019 23:35
Re: string not working
Hi Steffen
Then how it should be ?
Then how it should be ?
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: string not working
You've got two options:
Option 1 (recommended) - Use double quotes instead of single quotes in the set statement. Note that if you go this route, you should move the first double quote to the left of the variable name so that you get the benefit of quotes without the quotes actually being appended to the value of the string.
Option 2 - Include the single quotes in your if statement
Note that in both situations, your code will print "HI" instead of HI because echo does not need quotes.
Option 1 (recommended) - Use double quotes instead of single quotes in the set statement. Note that if you go this route, you should move the first double quote to the left of the variable name so that you get the benefit of quotes without the quotes actually being appended to the value of the string.
Code: Select all
set "res1=YES"
echo !res1!
if "!res1!" EQU "YES" echo "HI"
Code: Select all
set res1='YES'
echo !res1!
if "!res1!" EQU "'YES'" echo "HI"