i'm new in Linux, and i've been trying to run a script which processes all the files in a folder using ImageMagick's convert
(I rather do this task in Shell than using mogrify
, because as far as I know it doesn't save different files). The files have to be processed in 'last modified' order, so I used this code:
for file in `ls -1tr {*.jpg,*.png}`; do
# imagemagick processes with the filename...
done
This code breaks for files with spaces, and according to this answer using ls
is wrong for these purposes.
I also tried this solution from this response, but apparently I got it totally wrong (It raised an 'ambiguous redirect' error) and I decided I needed help.
while read LINE; do
...
done `(ls -1tr {*.png,*.jpg}`
So how do I get an ordered list of filenames for a loop? (It doesn't necessarily have to be a FOR...IN loop, it can be a WHILE, or anything.)