Nam G VU
Nam G VU

Reputation: 35364

How to have condition checking (if command) when use referred parameter of the command line?

In my batch file I have the script:

set myVar=/someLabel:"%1"

I want to write the if command for the above script that have the same meaning as below.

if <%1 not null> {
  myVar=/someLabel:"%1"
} 
else
{
  myVar=""
}

How can I do this?

[Edit]

The answer from user hfs works for me.

The full details of the if and set command is listed by user Dave Anderson.

Upvotes: 1

Views: 170

Answers (2)

Dave Anderson
Dave Anderson

Reputation: 12274

You will need to make sure you have delayed variable expansion enabled or the %1 will always be substituted with what is passed to the batch file regardless of your IF statement.

Here are excellent explanations of the DOS IF and DOS SET commands.

Upvotes: 1

hfs
hfs

Reputation: 2593

set myVar=
if not "%1" == "" set myVar=/someLabel:%1

Upvotes: 2

Related Questions