Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
rana
- Posts: 3
- Joined: 10 Mar 2020 08:25
#1
Post
by rana » 10 Mar 2020 23:34
Code: Select all
@echo off
set string=Hello
set ab = Batch
set b = Programming
if [%string%]==[] echo "String is empty"
if [%string%] NEQ [] echo String is %string%
echo %ab% %b%
The code should print out
... but instead it is printing out something else... i am attaching an image please have a look..
-
Attachments
-
- image 2.PNG (39.4 KiB) Viewed 4318 times
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#2
Post
by jeb » 11 Mar 2020 02:59
Hi rana,
it's a problem of your code formatting.
In batch you can't use spaces in a
SET expression, without side effects.
The correct syntax is
Code: Select all
SET var=content
or even better, to protect against invisible trailing white spaces
SET "var=content"
You used
set ab = Batch, this sets a variable with the name
ab<space> to the content
<space>Batch
-
rana
- Posts: 3
- Joined: 10 Mar 2020 08:25
#3
Post
by rana » 11 Mar 2020 04:27
Thank You jeb ,
, this forum is awesome