On Fri, Oct 15, 2021, 9:07 PM tolugboji via <help-bash@gnu.org> wrote:
> I have a list of image files and want to pass them in a loop with files
> coming through sorted by name.
>
> Have seen this approach
>
> for
>
> filename
>
> in
>
> `ls | sort -n`
>
> Are backticks still a good way to do this, as currently things are
> shifting towards $().
Bash sorts filenames lexically when using globs.
for file in *
does what you want without needing to use the sort utility and without
involving ls. It works even if filenames contain spaces or newlines - just
make sure you quote the variable when you're using its value
You don't need command substitution as a result, but when you do always use
$() and never use backticks.