mardi 7 septembre 2021

Create a batch file, for → if → for → if configuration. What if the value doesn't come in?

I am practicing creating a batch file

I created the code below as a batch file and ran it.

@echo off

for /f "delims=: tokens=2" %%a in ("hello:world") do set str1=%%a
if "%str1%"=="world" (
    echo %str1%.....
    for /f "delims=: tokens=1" %%b in ("hello:world") do set str2=%%b
    if "%str2%"=="hello" (
        echo %str2%......!!
    )
)

pause

result ::

world.....
Press any key to continue . . .

Where did my "hello" go?

How can I get both to be the output?

And if possible, can you tell me why?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire