crysis405
crysis405

Reputation: 1131

looping through a script setting

I have a script that takes in as one of its options a number from 0-1. I want to test what these different settings do so I want to loop through all of them. I want generated the numbers with this:

for ((i=0; i <= 10; i += 1)); do echo "scale=1; ${i}/10"| bc; done

However when I try this the bc doesn't evaluate the scale=1; ${i}/10 before it is taken by setting and so I end up using scale=1; ${i}/10 instead of the actual number I want:

for ((i=0; i <= 10; i += 1)); do Myscript --input testdata --setting "scale=1; ${i}/10"| bc; done

Upvotes: 0

Views: 26

Answers (2)

rici
rici

Reputation: 241671

You need to command-substitute echo "scale=1; ${i}/10" | bc if you want to include it as literal text:

 for ((i=0; i <= 10; i += 1)); do
   Myscript --input testdata --setting $(echo "scale=1; ${i}/10"| bc)
 done

However, it would be much easier to do the following:

 for i in 0 0.{1..9} 1; do
   Myscript --input testdata --setting $i
 done

Upvotes: 2

anubhava
anubhava

Reputation: 784918

Try this loop:

for ((i = 0; i <= 10; i++ )); do
    Myscript --input testdata --setting "$(bc -l <<< "scale=1; ${i}/10")"
done

Upvotes: 2

Related Questions