Number and string manipulation in bash

I wrote a little bash script (my first) that does the following:

sed -e 's/Alpha=0/Alpha=x/' -e 's/Beta=0/Beta=y/' <file.pov >tmpfile.pov
povray Width=480 Height=360 +Itmpfile.pov +Ofile_x_y.png 

everything works as intended, but now I would like to pack these two lines in a loop for x = 0: 30: 180 and y = 0: 30: 90 (change: I mean all possible combinations of x in {0, 30,60 , 90,120,180} and y in {0,30,60,90}).

So, for example, for x = 60 and y = 30, the code should behave as follows:

sed -e 's/Alpha=0/Alpha=60/' -e 's/Beta=0/Beta=30/' <file.pov >tmpfile.pov
povray Width=480 Height=360 +Itmpfile.pov +Ofile_60_30.png

I know this should not be too difficult, but for some reason, I just could not figure it out myself.

Sorry to bother you with your new questions!

+4
source share
2 answers

Use seq for loops:

for x in `seq 0 30 180`
do for y in `seq 0 30 90`
do sed -e 's/Alpha=0/Alpha='$x'/' -e 's/Beta=0/Beta='$y'/' <file.pov >tmpfile.pov
    fn="file_${x}_${y}.png"
    povray Width=480 Height=360 +Itmpfile.pov +O${fn}
done done

seq - great tool even if you don't need numbers

for i in `seq 10`
do call_me_ten_times
done
+1
source

bash, while:

while read x y; do
    sed -e 's/Alpha=0/Alpha='"$x"'/' -e 's/Beta=0/Beta='"$y"'/' <file.pov >"tmpfile${x}_$y.pov"
done < <(echo {0..180..30}' '{0..90..30} | tr ' ' '\n' | paste - -)

.

. . , , . , .

+1

All Articles