Christian writes: > sort -nt. +0 -1 +1 -2 +2 -3 +3 -4 > ... > I've been using that command syntax to sort IP's for several years...
Come to think of it, GNU sort could support that syntax even when asked to have POSIX 1003.1-2001 semantics, so long as argument reordering is in effect, since as far as POSIX is concerned "-1" is an option that lets 'sort' do what it wants. I installed the following patch, so that the above example will still work for you. Most of the code change is just for reindenting. 2006-06-28 Paul Eggert <[EMAIL PROTECTED]> * NEWS: Support obsolete usages like "sort +1 -2" even when conforming to POSIX 1003.1-2001, since this is a pure extension to POSIX. Problem reported by Christian in: http://lists.gnu.org/archive/html/bug-coreutils/2006-06/msg00220.html * doc/coreutils.texi (sort invocation): Document this. * src/sort.c (main): Implement this. Index: NEWS =================================================================== RCS file: /fetish/cu/NEWS,v retrieving revision 1.387 diff -p -u -r1.387 NEWS --- NEWS 26 Jun 2006 13:02:01 -0000 1.387 +++ NEWS 28 Jun 2006 23:47:03 -0000 @@ -77,6 +77,10 @@ GNU coreutils NEWS sort now reports incompatible options (e.g., -i and -n) rather than silently ignoring one of them. + sort now supports obsolete usages like "sort +1 -2" when conforming + to POSIX 1003.1-2001, since this is a pure extension to POSIX. + However, "sort +1" still sorts the file named "+1". + stat's --format=FMT option now works the way it did before 5.3.0: FMT is automatically newline terminated. The first stable release containing this change was 5.92. Index: doc/coreutils.texi =================================================================== RCS file: /fetish/cu/doc/coreutils.texi,v retrieving revision 1.333 diff -p -u -r1.333 coreutils.texi --- doc/coreutils.texi 27 Jun 2006 20:26:12 -0000 1.333 +++ doc/coreutils.texi 28 Jun 2006 23:47:06 -0000 @@ -3681,11 +3681,13 @@ numbers of leading blanks in fields can Keys can span multiple fields. @vindex _POSIX2_VERSION [EMAIL PROTECTED] POSIXLY_CORRECT On older systems, @command{sort} supports an obsolete origin-zero syntax @[EMAIL PROTECTED] [EMAIL PROTECTED] for specifying sort keys. This obsolete behavior can be enabled or disabled with the @env{_POSIX2_VERSION} environment variable (@pxref{Standards -conformance}). +conformance}); it can also be enabled when @env{POSIXLY_CORRECT} is +not set by using the obsolete syntax with @[EMAIL PROTECTED] present. Scripts intended for use on standard hosts should avoid obsolete syntax and should use @option{-k} instead. For example, avoid Index: src/sort.c =================================================================== RCS file: /fetish/cu/src/sort.c,v retrieving revision 1.336 diff -p -u -r1.336 sort.c --- src/sort.c 25 May 2006 16:47:43 -0000 1.336 +++ src/sort.c 28 Jun 2006 23:47:06 -0000 @@ -2320,37 +2320,42 @@ main (int argc, char **argv) { case 1: key = NULL; - if (obsolete_usage && optarg[0] == '+') + if (optarg[0] == '+') { - /* Treat +POS1 [-POS2] as a key if possible; but silently - treat an operand as a file if it is not a valid +POS1. */ - key = new_key (); - s = parse_field_count (optarg + 1, &key->sword, NULL); - if (s && *s == '.') - s = parse_field_count (s + 1, &key->schar, NULL); - if (! (key->sword | key->schar)) - key->sword = SIZE_MAX; - if (! s || *set_ordering (s, key, bl_start)) + bool minus_pos_usage = (optind != argc && argv[optind][0] == '-' + && ISDIGIT (argv[optind][1])); + obsolete_usage |= minus_pos_usage & ~posixly_correct; + if (obsolete_usage) { - free (key); - key = NULL; - } - else - { - if (optind != argc && argv[optind][0] == '-' - && ISDIGIT (argv[optind][1])) + /* Treat +POS1 [-POS2] as a key if possible; but silently + treat an operand as a file if it is not a valid +POS1. */ + key = new_key (); + s = parse_field_count (optarg + 1, &key->sword, NULL); + if (s && *s == '.') + s = parse_field_count (s + 1, &key->schar, NULL); + if (! (key->sword | key->schar)) + key->sword = SIZE_MAX; + if (! s || *set_ordering (s, key, bl_start)) + { + free (key); + key = NULL; + } + else { - char const *optarg1 = argv[optind++]; - s = parse_field_count (optarg1 + 1, &key->eword, + if (minus_pos_usage) + { + char const *optarg1 = argv[optind++]; + s = parse_field_count (optarg1 + 1, &key->eword, N_("invalid number after `-'")); - if (*s == '.') - s = parse_field_count (s + 1, &key->echar, + if (*s == '.') + s = parse_field_count (s + 1, &key->echar, N_("invalid number after `.'")); - if (*set_ordering (s, key, bl_end)) - badfieldspec (optarg1, + if (*set_ordering (s, key, bl_end)) + badfieldspec (optarg1, N_("stray character in field spec")); + } + insertkey (key); } - insertkey (key); } } if (! key) _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils