I didn't actually check your script code - but the way you are trying to call it is incorrect. Look what is displayed when you try your command line with "echo" instead of calling GIMP:
$ echo "(batch-rotate \"*.JPG\" 1)" -b '(gimp-quit 0)'
(batch-rotate "*.JPG" 1) -b (gimp-quit 0)
That is, the *.JPG
pattern is enclosed in the quotes used to invoke the script, and bash does not expand it to the file list.
You may fight your way with the command line syntax, and then fix your script - there is some other error in it, else, it would just fail to find a file named "*.JPG" and end. However, I'd advise you to write your script in Python instead of script-fu. It is a higher level multi-purpose language, instead of a stripped down academic interpreter like the built-in script-fu, and can easily read all JPG files in a directory with a construct like:
import glob
for filename in directory + "/*.JPG":
<code>
instead of trying to hack ways to pass list of files through the command line, and then hacking ways of extracting each filename from a list.
I am sorry to recommend another language, but unless you are already proficient in Scheme (the script-fu language), learning Python instead will be more useful to you in many other situations - including as scripting language for other programs, and including having other image libraries like PILLOW, pygame, vips, python-gegl, python-magick, python-opencv, all of which can rotate or flip images as well as the Python-GIMP bindings.