Page 1 of 1

Setting variable problem in .bat or .cmd script ?

Posted: 10 Sep 2020 15:39
by 03bluecoupe
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

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

Posted: 10 Sep 2020 19:22
by Squashman
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%