Liste des Groupes | Revenir à cu shell |
I'm using ksh here...Can you use an array? E.g. (bash, I don't know ksh, but could be similar)
I can set the shell parameters in numerical order
$ set {1..100}
then sort them _lexicographically_
$ set -s
Or do both in one
$ set -s {1..100}
I haven't found anything to sort them _numerically_ in shell.
What I'm trying to do is iterating over files, say,
P1.HTM P10.HTM P11.HTM P2.HTM P3.HTM P4.HTM P5.HTM P6.HTM P7.HTM
P8.HTM P9.HTM
in numerical order.
Setting the files as shell arguments with P*.HTM will also produce
lexicographical order.
The preceding files are just samples. It should work also if the
numbers are non-consecutive (say, 2, 10, 10000, 3333333) so that
iterating using a for-loop and building the list is not an option.
(Ideally I'd also like to handle names with two numbers "A35P56.txt"
and irregular string components (lowercase, say, "page310ch1.txt"),
but that's just a nice-to-have. - I might make use of 'sort'?)
But the primary question is; how to organize/iterate the arguments
*numerically* _in shell_? (If that's possible in some simple way.)
N.B.: I prefer not to use external commands like 'sort' because of
the negative side effects and bulky code to handle newlines and
blanks in filenames, and messing around with quotes.
Janis
Les messages affichés proviennent d'usenet.