Bash for loop ends after 300 loops?
I have a very interesting problem, in my bash script below, the for loop somehow halts always after 300 loops ( and I sometimes need it to perform over 600 ).
#!/bin/bash
for i in `seq $1 $2`;
do
composite $i".png" $i"_temp.png" $i"_out.png"
done
I had no trouble running the same command looped in other languages with over 300 loops. I don't know what开发者_如何学C happens with bash.
Also, I noticed that after the 300th loop, the script doesn't exit, but instead "pauses".
I'm currently using a workaround for this problem by running the script from 1 to 250, then from 251 to 500, etc.
I wondered if this might be a limit on the amount of output that can be substituted in backticks, but I can't reproduce that on my Linux system, and it's surprising that you apparently don't see any error message. However, something you could try as an alternative to your current script is to still use seq
but pass its results into a while read
loop, which would avoid the substitution:
seq $1 $2 | while read i
do
composite $i".png" $i"_temp.png" $i"_out.png"
done
Why don't you use a while loop?
i=0
while [ $i -le $1 ]
do
composite $i".png" $i"_temp.png" $i"_out.png"
i=$((i + 1))
done
No need to use external commands
for ((i=$1; i<=$2 ;i++))
do
composite "${i}.png" "${i}_temp.png" "${i}_out.png"
done
精彩评论