Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Set variable to null

3,292 views
Skip to first unread message

CenturionX

unread,
Oct 9, 2008, 2:12:40 PM10/9/08
to
Hello everybody,

Does somebody knows how to set a variable to null??

I put a set of variables at the beginning of my batch file like that
VAR1=
VAR2=
but i notices it causes the ERRORLEVEL be 1

How can i set a null value to these variables???

Thanks.

Esra Sdrawkcab

unread,
Oct 9, 2008, 4:11:06 PM10/9/08
to

The Clue is in the Question

SET VAR1=

but there's no point as any nonexistent variable equates to null anyway.

Matthias Tacke

unread,
Oct 9, 2008, 5:36:23 PM10/9/08
to

As you are posting from xp you might try:

for %%A in (VAR1 VAR2) do if defined %%A set "%%A="

HTH
Matthias

billious

unread,
Oct 9, 2008, 7:45:13 PM10/9/08
to

"CenturionX" <darwinb...@gmail.com> wrote in message
news:1d136a89-3988-446f...@l33g2000pri.googlegroups.com...

Interesting observation - but not quite accurate.

set var=

will set ERRORLEVEL to 1 IF var undefined, but leave ERRORLEVEL unchanged if
var is defined
whereas set var=somethingelse will leave ERRORLEVEL unchanged regardless
(empirically determined)

if defined var set var=

would appear to stop the problem you appear to be encountering.


CenturionX

unread,
Oct 26, 2008, 3:51:52 PM10/26/08
to
On Oct 9, 7:45 pm, "billious" <billious_1...@hotmail.com> wrote:
> "CenturionX" <darwinbaldr...@gmail.com> wrote in message

Thanks for the help.

m406...@gmail.com

unread,
Sep 23, 2017, 10:56:56 AM9/23/17
to
SET VAR1=%

Using SET VAR1= will delete the variable completely. E.g. you would not be able to echo VAR1 as it doesn't exist.
0 new messages