Pavel
Pavel

Reputation: 77

Use a bash file to loop over other bash files with different paramer values

I have a shell file script.sh with the following commands:

#!/bin/sh
#SBATCH --partition=univ2       
#SBATCH --nodes=2               
#SBATCH --ntasks-per-node=13    
mpirun -n 25 benchmark.out $param

where param is an integer from the set {1,2,...,10}. Here param is a command line argument that is passed over to the executable benchmark.out. I want to create another shell file master.sh (in the same directory as script.sh) which would contain a loop over param (from 1 to 10), such that upon each iteration, script.sh is executed with a given value of param. How should this file look like? Thank you.

Upvotes: 0

Views: 35

Answers (1)

Oo.oO
Oo.oO

Reputation: 13385

Master

#!/bin/bash

for param in `seq 1 1 10`; do
  ./script.sh $param
done

Script

#!/bin/sh
#SBATCH --partition=univ2       
#SBATCH --nodes=2               
#SBATCH --ntasks-per-node=13    
mpirun -n 25 benchmark.out $1

Upvotes: 1

Related Questions