I am sure this is a good way to this using only the shell.
But I have previously moved all the files I need to process to temporary folder.
Then the shell command can do something like.
convert /tempfolder/*.jpg ~/Desktop/animated.gif
The above is just a pseudo example.
You can find a macro which uses this here to merge pdf-files.
Hope you can modify to your need.