If using normal assignment, no spaces are allowed so you need:
i=0
(note that the semicolon is unnecessary). If you really want nicely formatted expressions, you can use the:
((i = 0))
statement. I would also use it in place of expr
as well since expr
is an external command with all the cost of process creation (this usually doesn't matter for quick and dirty scripts where only a few external processes are created but, if you find it happening a lot, you can get a very decent performance improvement).
Unfortunately, it doesn't like floating point but you can easily emulate it in your case since your numbers simply range from 0.0
through 0.9
(i.e., only the fractional part changes):
((i = i + 1))
and running it from 0 to 9, modifying the other lines to suit the new range.
The only other thing I'd check would be:
while [$i -l 1]
I think [
is treated as a command so you may need spaces (and you definitely need a real comparison operator):
while [ $i -lt 1 ]
And [
is typically also an external program, I prefer the bash
built in [[
.
Tying all those elements together:
#!/bin/bash
set -e
set -u
((i = 0))
while [[ $i -lt 10 ]] ; do
src/meshpro input/martini.off video/noise/image0.$i.off -noise 0.$i
src/meshview video/noise/image$i.off -output_image \
video/noise/image0.$i.jpg -exit_immediately
((i = i + 1))
done
You'll notice a difference with the output in that previously your zero file would have been image0.off
with the others image0.X.off
, whereas now it's image0.0.off
. I think that's beneficial as well since it gives all your files exactly the same format.
If you disagree, it would be a simple matter to add:
mv video/noise/image0.0.jpg video/noise/image0.jpg
to the end of your script.