Your number already has 2 decimal places. Why do you need to use printf? If I remember correctly (I donβt have a shell for testing here), it simply fills up to 2 decimal places when used with these flags. Personally, I like xargs:
seq 23 42 | xargs -n1 sh ../myprogram
You can use the -w argument to seq , which fills the numbers with zeros if necessary, so they have the same width.
It turns out seq is specific to Linux. Thanks to Dave for comments for his clarification (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 you to easily run your commands in parallel to a certain limit, can transfer more than one number at a time, and allows you to use other flexible options. Like Dave, I recommend that you give up sh and put it in your shell script instead of the first line:
Then just do your things like
printf '%02i\n' {23..42} | xargs -n1 ../myprogram
This is more general and allows your script to also be called when the exec C library is called (at least on Linux, in this case).
Johannes Schaub - litb
source share