I am developing a script in which I need the user to select from a list that provides them with the tool they want to use and that depending on this input takes them to the other part of the code. However, since I don’t know much about batch language, I asked ChatGPT and with similar projects that I saw on this site, I tried to do it. The problem in general is when the user types the number and presses enter, the program closes immediately. This is my code:
echo 1. Temporary Cleaning.
echo 2. Installation of Applications.
echo 3. Application Update.
echo 4. Exit
echo.
echo.
:digitnumber
set /p ntool= Enter the number of the tool you need:
set "vnumber=false"
set "nvalid= 1 2 3 4 "
for %%A in (%invalid%) do ( if "%ntool%"=="%%A" (
set "vnumber=true"
goto validnumber
)
)
:validnumber
if "%vnumber%"=="true" (
if "%ntool%"=="1" (
echo You have selected option 1.
) else if "%ntool%"=="2" (
echo You have selected option 2.
) else if "%ntool%"=="3" (
echo You have selected option 3.
) else if "%ntool%"=="4" (
echo You have selected option 4.
)
) else (
echo Invalid selection. Please select a valid option (1-4).
goto enter number
)
pause
`
If you can help me I would really appreciate it.
I ran the code part by part and apparently the problem lies after checking whether the variable is a valid number or not. But I do not know what to do
Juan Jose Ospina Valencia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.