0

I'm trying to run this script:

SET 0=http://www.zap.co.il/
SET 1=https://sa.zap.co.il/
SET 2=https://vpc.must.co.il/bo1/MainForm.asp
SET 3=https://direct-israline.co.il
SET 4=https://mypost.israelpost.co.il

setlocal EnableDelayedExpansion

for /l %%x in (1, 1, 5) do (
    SET /a link=!RANDOM! %%5
    start !link!
    set /a num=!RANDOM! %%20+5
    TIMEOUT !num! /nobreak
)

but this won't run.

Can anyone help?

double-beep
  • 5,031
  • 17
  • 33
  • 41
  • 7
    The first character of the variable name [must not be numeric](https://ss64.com/nt/syntax-percent.html). It is a common practice to prefix variable names with either an _undescore_ or a _dollar sign_ `_variable` or `$variable`, these prefixes are not required but help to prevent any confusion with the standard built-in Windows Environment variables or any other other command strings. – JosefZ Dec 03 '18 at 17:04
  • If `link` variable contains a digit (`3` for example) then `start !link!` is the same as `start 3`. You need an _additional_ expansion of `3` variable. This can be done via `for %%r in (!link!) do start !%%r!` as described at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990). **Note:** although a variable should not start in digit (as others already said), this point is not the cause of your problem... – Aacini Dec 03 '18 at 23:54

1 Answers1

0

If you are using an array I suggest you to use the standard array notation, with the subscript enclosed in square braquets:

@echo off
setlocal EnableDelayedExpansion

SET link[0]=http://www.zap.co.il/
SET link[1]=https://sa.zap.co.il/
SET link[2]=https://vpc.must.co.il/bo1/MainForm.asp
SET link[3]=https://direct-israline.co.il
SET link[4]=https://mypost.israelpost.co.il

for /l %%x in (1, 1, 5) do (
    SET /a ran=!RANDOM! %%5
    for %%r in (!ran!) do start !link[%%r]!
    set /a num=!RANDOM! %%20+5
    TIMEOUT !num! /nobreak
)

For a complete description on array management in Batch files, see this answer.

Aacini
  • 65,180
  • 12
  • 72
  • 108
  • That is good! Could you select this as Best Answer? Doing that will give rep points to both you and me, and inform others that the questions was solved already. – Aacini Dec 04 '18 at 17:56