#!/bin/sh

ls IMG_*.JPG > lst

awk '
BEGIN{
  printf "gmic -input";
}
{
  printf " " $0;
  n++;
}
END{
  for(i=1; i<=n-1; i++){
    printf " -add[0] [" i "]";
  }
  printf " -div[0] " n;
  print " -output[0] dark.jpg"
}
' lst > dark.tmp

bash dark.tmp


