CathalMF
CathalMF

Reputation: 10055

Batch file IF condition. Syntax incorrect.

Working with an old system at the moment and have a batch file which does a bunch of work.

Im trying to add an IF condition to compare strings but its just not working for me.

SET ENABLED=%1

IF "%ENABLED%"=="n"
(
    echo "doing some work"
)

The batch file is executed like

MyBatch.bat n

However this is resulting in an error:

The syntax of the command is incorrect.

Whats wrong with this?

Upvotes: 0

Views: 906

Answers (1)

Bill_Stewart
Bill_Stewart

Reputation: 24525

Batch file (cmd.exe shell script) syntax can be a challenge.

The answer in this case is to keep the open parenthesis (() on the same line as the if command.

Upvotes: 1

Related Questions