[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Loop with files coming through sorted by name
From: |
Dennis Williamson |
Subject: |
Re: Loop with files coming through sorted by name |
Date: |
Fri, 15 Oct 2021 21:50:32 -0500 |
On Fri, Oct 15, 2021, 9:47 PM Dennis Williamson <dennistwilliamson@gmail.com>
wrote:
>
>
> 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.
>
Oh, by the way, sort -n sorts numerically - not by name. If that's
actually what you're doing then you should use the find ... print0 |
sort-zn form.
>
- Re: Loop with files coming through sorted by name, (continued)
- Re: Loop with files coming through sorted by name, Dennis Williamson, 2021/10/16
- Loop with files coming through sorted by name, tolugboji, 2021/10/16
- Re: Loop with files coming through sorted by name, Daniel Mills, 2021/10/18
- Re: Loop with files coming through sorted by name, Greg Wooledge, 2021/10/18
- Loop with files coming through sorted by name, tolugboji, 2021/10/18
- Re: Loop with files coming through sorted by name, Chet Ramey, 2021/10/18
- Loop with files coming through sorted by name, tolugboji, 2021/10/18
- Re: Loop with files coming through sorted by name, Chet Ramey, 2021/10/19
- Loop with files coming through sorted by name, tolugboji, 2021/10/19
Re: Loop with files coming through sorted by name, Dennis Williamson, 2021/10/15
- Re: Loop with files coming through sorted by name,
Dennis Williamson <=