Your number already has 2 decimal places. Why do you need to use printf then? If i remember correctly (haven't got a shell for testing here), it just pads the number up to 2 decimals when used with those flags. Personally, i like xargs:
seq 23 42 | xargs -n1 sh ../myprogram
You can use the -w
argument for seq
, which pads the numbers with zeros if necessary, so they have all the same width.
It turns out seq
is linux specific. Thanks for Dave in the comments for figuring it out (his answer). Use printf
directly, without a loop:
printf '%02i\n' {23..42} | xargs -n1 sh ../myprogram
I like to use xargs
, because it allows easily running your commands in parallel up to some limit, can pass more than one number at once and allows other flexible options. Like Dave, i recommend you to drop the sh
from it, and place it into your shell script, as first line instead:
#!/bin/sh
.....
Then just execute your stuff as
printf '%02i\n' {23..42} | xargs -n1 ../myprogram
This is more generic, and allows your script also to be called by the exec
C library calls (at least in Linux, that's the case).