You are not logged in.
Pages: 1
my overbloated code currently is:
SET KEY1=&SET KEY2=&SET KEY3=&SET KEY4=&SET KEY5=&SET KEY6=&SET KEY7=&SET KEY8=&SET KEY9=&SET KEY10=&SET KEY11=&SET KEY12=&SET KEY13=&SET KEY14=&SET KEY15=&SET KEY16=&SET KEY17=&SET KEY18=&SET KEY19=&SET KEY20=&SET KEY21=&SET KEY22=&SET KEY23=&SET KEY24=&SET EY25=&SET KEY26=&SET KEY27=&SET KEY28=&SET KEY29=&SET KEY30=&SET KEY31=
How can I shorten this? All I am trying to do is clear/kill values of key1-key31. I would like some kind of loop to do this in a single or few commands(like for /f command), and also one that can just clear/kill the values of KEYx (x representing any amount of numbers).
cmd, vbs, ps, bash
autoit, python, swift
Offline
the FOR command is very powerful. There are many options for it. You can loop through a cetain set of values, sort through an output of an program execution or even loop through numbers like good ol' for loops are usually done.
You would use the FOR /L loop to loop through a set of numbers.
In this case, you can easily set an enviornment variable as an enviornment variable name:
SET %_variable%=Value
So in this case all you would do is:
for /L %%g in (1,1,31) do set KEY%%g=
Offline
On a similar theme to what //[T.O.P]// suggests, I use this subroutine to "flush" all variables that are prefixed with the string(s) that are passed to it:
:flush
for %%f in (%*) do (
(for /f "usebackq tokens=1 delims==" %%a in (`set %%~f`) do (set %%~a=) ) 2>nul
)
goto :EOF
So you'd want to be doing this: "call :flush KEY" but you could easily "flush" numerous variable prefixes, thus: "call: flush THIS THAT OTHER"
cmd | *sh | ruby | chef
Offline
Pages: 1