Reputation: 1235
I have a file script.sh that contains a specific command that I want to run. Every time I do ./script.sh I execute this script. This script contains a unique identifier, for example:
... load id_1 /path ...
What I want to do is to run this script n times using different ids. For example the first time it run it will use id_1, the second one id_2 and so on. How can I do that?
Upvotes: 0
Views: 573
Reputation: 851
If your script.sh file contains entry like you have posted:
... load id_1 /path ...
Then one option is to edit it and replace 1 with $1 as listed below:
... load id_$1 /path ...
Run this bash one liner from your shell:
$ for i in $(seq 1 10); do ./script.sh $i ; done
some explanation
seq will print a sequence of numbers e.g. 1 to 10
For example, the below command will print digits from 1 to 100 on your shell
$ seq 1 100
Next is ./script.sh $i
It will pass value of variable $i, created while cycling seq, to script.sh
The instruction id_$1 inside your script.sh will replace $1 with value passed to it from one liner
Upvotes: 1