0

I'm working on a batch file that sets the variables a through z and the default value should be y (for y or n). I can't find a way to loop through all the letters and set them all to "y" do loop a-z set=y

Currently, using

set a=y
set b=y
set c=y 
echo.&echo.&echo Do you want to:
set /P a=Set a RESTORE point? Y/N?....
set /P b=Disable Search and Prefetch? Y/N?....
set /P c=Close all running programs? Y/N?....
2
  • Any reason you want to preset the variables instead of taking the traditional approach of having the script act on the value of the variable after the fact? Commented Feb 15, 2022 at 19:42
  • FOR %%G IN (A B C D E F etc....) DO set "%%G=Y" Commented Feb 15, 2022 at 19:56

1 Answer 1

1

The standard way:

for %%v in (a b c d e ... x y z) do set "%%v=y"

The smart-and-tricky way:

@echo off
setlocal EnableDelayedExpansion

for /L %%i in (97,1,122) do (
   cmd /C exit /B %%i
   set "!=ExitCodeAscii!=y"
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.