Search notes:

cmd.exe: goto

goto is affected by whether command extensions are enabled or disabled.

Let the user choose an option

The following example uses set /p to print Choose either foo, bar or baz! and assign the entered option to the environment variable %chosen%.
It then uses if … equ … to compare the entered value to the hard coded values foo, bar or baz. Depending on the chosen value, the if statement then uses goto to jump to a label which simply prints what the user has chosen.
@echo off

:choose
@set /p chosen="Choose either foo, bar or baz! "

if "%chosen%" equ "foo" goto foo_chosen
if "%chosen%" equ "bar" goto bar_chosen
if "%chosen%" equ "baz" goto baz_chosen

@echo "YOu haven't chosen a valid option, try again!"
goto choose

:foo_chosen
@echo Here's Foo
@goto finish

:bar_chosen
@echo Here's Bar
@goto finish

:baz_chosen
@echo Here's Baz

:finish
Github repository about-cmd.exe, path: /commands/goto/menu.bat

See also

Other cmd.exe commands

Index