-1

I want to run several jobs in parallel using the a script that does serial calls to a parameterized script and submits it as a background job on each call. It's for a brute force script which on each call will run 1k of 10k total combinations.

The following is my first hack at it.

#!/bin/bash
for i in $(seq 10)
do
    ./tmp/tmpsky/bd25Par.sh (i*1000-1000) (i*1000) &
done

I want $1 to evaluate as 0,1000,2000 etc...and $2 to evaluate to 1000,2000,3000 etc.

The & is to submit the script as a background job. The called module will pass $1 and $2 to be used with seq as follows

#/bin/bash/
for n in $(seq $1 1 $2)
do
...`

The first script fails with unexpected token 'i*1000-1000'

What have I done wrong?

Info5ek
  • 493

1 Answers1

1

The first script fails with unexpected token 'i*1000-1000'

What have I done wrong?

The obvious error is that you are actually not calling the variable $i in your loop:

for i in $(seq 10)
do
    ./tmp/tmpsky/bd25Par.sh (i*1000-1000) (i*1000) &
done

It should be:

for i in $(seq 10)
do
    ./tmp/tmpsky/bd25Par.sh ($i*1000-1000) ($i*1000) &
done

Thus; use $i when using the variable. i in itself will not work.

As far as doing math in the shell, see comment number 2.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255