mardi 16 février 2021

An IF statement that checks and executes a command per each set variables in a windows batch file

I need help to see if I can get a command to be executed per each set variable in a windows batch. Note that all that changes is the number for each variable. If in the future I were to add more of these variables/TRIMApps, this IF statement would continue to catch it. So I was guessing that I can do something like this with an IF statement, as shown below. However, I don't see how I can "wildcard" the string "str", if that is the solution, of course. Maybe a loop is needed?

SET TRIMAPP1=APP1
SET TRIMAPP2=APP2
SET TRIMAPP3=APP3
SET TRIMAPP4=APP4
SET TRIMAPP5=APP5

echo %var% |findstr /b "str" >nul && (
  echo yes
  set another variable
  set another variable
  run a command
) ELSE (
  echo no
)

I'm very new with IF statements in Windows batch files. Your help is very much appreciated.

Aucun commentaire:

Enregistrer un commentaire