help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loop with files coming through sorted by name


From: tolugboji
Subject: Loop with files coming through sorted by name
Date: Sat, 16 Oct 2021 04:03:57 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Saturday, October 16th, 2021 at 3:31 AM, Seth David Schoen 
<schoen@loyalty.org> wrote:

> Seth David Schoen writes:
>
> > Typically people will suggest instead using the find command, either
> >
> > with the -exec flag or with the -print0 flag. This is extensively
> >
> > described in
> >
> > https://stackoverflow.com/questions/9612090/how-to-loop-through-file-names-returned-by-find
> >
> > A disadvantage there is that the command run by the -exec can only be
> >
> > a single command, not a bunch of shell scripting or even a pipeline.
>
> I didn't realize, but there is a newer approach which involves a bunch of
>
> historically recent bashisms
>
> https://stackoverflow.com/questions/23356779/how-can-i-store-the-find-command-results-as-an-array-in-bash/54561526#54561526
>
> You can thus do
>
> readarray -d "" myarray < <$(find . -type f -print0 | sort -zn)
>
> for i in "${myarray[@]}"; do
>
> arbitrary shell stuff with "$i"
> ===============================
>
> done
>
> Classical Bourne shell scripting it isn't. :-)


What's the opinion about

  for flimg in $( find $fdir type f -name "$fnam-*.png" | sort -n )
  do
    echo "$flimg"
  done

There is a number after "-" (e.g. edvart-01.png edvart-02.png ...)

Perhaps using the following is much better?

for file in ${fdir}/$fnam-*.png



reply via email to

[Prev in Thread] Current Thread [Next in Thread]