0

I would like to execute 120 models a shell script for 100 years. i.e.

start=1900; end=2000
using model1,model2, model3 and so on until 120 models

I can execute them manually with following command: (lets say 3 models)

exec "${script_dir}myscript $start $end $model1 $model2 $model3"

How can I use a loop to extend the above command something like

exec "${script_dir}myscript $start $end $model1 $model2 $model3 $model4 ..... $model120"
3
  • Please specify how the 120 models should be distributed over 100 years. Commented Jun 28, 2016 at 3:57
  • Are you really looking for a POSIX-compliant solution, as your tags suggest, or is bash acceptable (which would simplify the answer)? Commented Jun 28, 2016 at 4:12
  • I am looking something which will be look like exec ${script_dir}myscript $start $end $model1 $model2 $model3 and so on until $model120 Can you please suggest Commented Jun 28, 2016 at 5:36

1 Answer 1

3
start=1900
end=2000
command="\${script_dir}myscript \$start \$end"
i=1

while [ $i -le 120 ]
do
    command="$command \$model$i"
    i=`expr $i + 1`
done

exec $command

This script will simply do a for loop from 1 to 120 and concatenate all the models to your command.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer. But I am looking something which will be look like exec "${script_dir}myscript $start $end $model1 $model2 $model3 and so on until $model120 Can you please suggest
Do you need the variable values or just this exact text?
I need the exact text. Because this command will provide the path of model to myscript.
I edited the script by escaping the $ signs in the command. This way you'll get the exact text. Not exactly sure what you're trying to do, because this will literraly try to execute the command ${script_dir}myscript which will probably result in "not found".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.