Sujet : Re: Is 'ls -v' the Final Solution? (Was: Numerically sorted arguments (in shell))
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 24. Jun 2024, 16:01:03
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5bu70$vaas$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 24.06.2024 15:22, Kenny McCormack wrote:
In article <7cbgkkx149.ln2@slack15-a.local.uk>,
...
I finally remembered which tool has "versionsort(3)" -- it's ls:
>
$ ls -1
test10.txt
test1.txt
test2.txt
>
$ ls -v -1
test1.txt
test2.txt
test10.txt
>
Does that help?
>
>
I didn't realise it could work like that. Thanks.
To OP: Does "ls -v" meet your criteria?
Yes, at least partly. (Why are you asking?)
It meets it in the way that it's ready available and usable
as external command. It does not solve the shell internal
additional globbing feature (like in Zsh) that would be
nice and preferable.
In the quoted form as 'ls -vQ' some pathological filenames
are (seemingly) handled, but there's some hassle with the
quotes in the subsequent processing steps to expect (or so
I think). That's why an integrated form supported by shell
would IMO be an advantage; so that we could simply write
set -o numsortglob # <-- hypothetical shell feature
for f in version*.gz
do ...
done
At least the output from code like
for f in $(ls -vQ) ; do printf "'%s'\n" "$f" ; done
or
ls -vQ | while IFS= read -r f ; do printf "'%s'\n" "$f" ; done
indicates that there's still something to do, and without
the 'ls -Q' quotes the (pathological) newlines are an issue
(at least).
I think it's a typical problem that would best be solved
by a shell built-in feature. (External tools may take you
part of the road and probably with additional effort for
common subsets of the task but probably not bullet-proof.)
Janis