Setting variable problem in .bat or .cmd script ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
03bluecoupe
Posts: 1
Joined: 10 Sep 2020 15:20

Setting variable problem in .bat or .cmd script ?

#1 Post by 03bluecoupe » 10 Sep 2020 15:39

Hi all, forum newbie here. I'm an old AIX/Linux guy but my wife has a side business that I need to support so I'm in the DOS world...
I thought I was trying to do something extremely simple. Either that's not the case or I'm just flat being dense....

In a .bat/.cmd file run from the command prompt, I just want to do:

If $Variable3 is NULL then set Variable3=0

Then printing out Variable_3 (just as a sanity check) I've tried every syntax I can find and think of, as well as a few others. ;)
I'm just at a loss. It seems like it should be a straight forward "if then else" statement but....

Anyone set me straight?

Steve

Squashman
Expert
Posts: 4194
Joined: 23 Dec 2011 13:59

Re: Setting variable problem in .bat or .cmd script ?

#2 Post by Squashman » 10 Sep 2020 19:22

You can see the proper syntax for a command by typing the command name followed by a question mark from the cmd prompt.

Code: Select all

if /?
But it is usually a lot easier just to reference Microsoft's documentation but I usually use SS64.
https://ss64.com/nt/

Code: Select all

IF NOT DEFINED variable3 set "variable3=0"
echo %variable3%
or

Code: Select all

IF "%variable3%"=="" set "variable3=0"
echo %variable3%

Post Reply