This is a Bash question about renaming / incrementing file names with a series of 'for' loops. I don't understand the behavior...
Working with the ImageMagick
If I do this with say, 3 source files:
$ convert *.miff dir/%d.miff $ convert *.miff dir1/%d.miff
I get the expected behavior, with
dir1 both containing the files
0.miff 1.miff 2.miff - this is the required behavior. However
convert reads all the source images into memory and soaks up resources (Try this with 30 - 40 large image files), not necessarily in strict file order.
This is better, file by file, in strict order, to satisfy the end processing requirement, one file at a time
$ for var in `ls -v *.miff`; do convert $var dir/%d.miff; done $ for var in `ls -v *.miff`; do convert $var dir1/%d.miff; done
But, I get
0.miff 1.miff 2.miff in
3.miff 4.miff 5.miff in
I have tried assigning different variables to
$var for each loop and using variations on
%d.miff such as
$((x++)).miff. No change - incrementing continues upwards instead of resetting to '0' at each 'for' loop.
I have searched for a meaningful answer but suspect this is a behavior embedded in bash and appears to be related to the use of the
The question is simplified to avoid overwhelming the reader but there are 4 loops, each doing different things, culminating in recombination of the images created in the 4 directories; as follows with the modified script, per Jesse_p's answer:
x=(0) for i in `ls -v *.miff`; do convert "$i" -depth $depth -roll +0+0 -sample 50% B/"$((x++)).miff" done x=(0) for i in `ls -v *.miff`; do convert "$i" -depth $depth -roll +0+1 -sample 50% G/"$((x++)).miff" done x=(0) for i in `ls -v *.miff`; do convert "$i" -depth $depth -roll +1+0 -sample 50% g/"$((x++)).miff" done x=(0) for i in `ls -v *.miff`; do convert "$i" -depth $depth -roll +1+1 -sample 50% R/"$((x++)).miff" done for ((R=0,G=0,g=0,B=0;R<=101;R+=1,G+=1,g+=1,B+=1)); do convert R/$R.miff G/$G.miff B/$B.miff depth $depth \ -colorspace sRGB -combine "$((x++))_$name.tiff" done