Quick and dirty:
#!/bin/bash ls *.jpg | while read file do number=`echo $file | tr -dc 0-9`; if [ $((number % 2)) -eq 0 ]; then nextnumber=`echo $number + 1 | bc`; nextfile=`echo $file | sed s/$number/$nextnumber/`; outfile=`echo $file | sed s/$number/$number$nextnumber/`; montage $file $nextfile -gravity center -geometry +1+1 -tile 1x2 $outfile fi done
You said to apply the montage to the odd files but provided even in your example. The code above will work for even. If you need the odd files to be first just change this line:
if [ $((number % 2)) -eq 0 ]; then
to be this:
if [ $((number % 2)) -eq 1 ]; then