1

I'm trying to determine if option is define statement/option for the VC compiler (/DSOME_OPTION=1 e.g.). Here is the part of options handling loop, which return error "Unexpected at this time: =option.". I've used search substring solution from StackOverflow: Batch file: Find if substring is in string (not in a file)

setlocal enabledelayedexpansion
:loop
if not "%~1"=="" (
    rem all defines
    set "option=%~1"
    if x%option:/D=%==x%option% (
        set DEFINE_STR=%DEFINE_STR% %~1
        echo "DEFINE_STR=%DEFINE_STR%"
        pause
    )
    shift
    goto :loop
)
Community
  • 1
  • 1
Anton Kochkov
  • 1,117
  • 1
  • 9
  • 25

1 Answers1

2

try this:

@echo off

setlocal enableDelayedExpansion
set "DEFINE_STR="
:loop
if not "%~1"=="" (
    rem all defines
    set "option=%~1"
    if "!option:/D=!" == "!option!" (
        set "DEFINE_STR=!DEFINE_STR! %~1"
        echo "DEFINE_STR=!DEFINE_STR!"
        pause
    )
    shift
    goto :loop
)
endlocal

In this question you can find more info -> Why can I not get a substring of a delayed expansion variable in an if statement?

Community
  • 1
  • 1
npocmaka
  • 55,367
  • 18
  • 148
  • 187