split: make the last specified --{hex,numeric} set the start

Given the FROM argument is interpreted as a different base
for --hex-suffixes and --numeric-suffixes, it makes more
sense for a previous start value to be discarded.

* doc/coreutils.texi: Mention this for --hex-suffixes,
and also mention the FROM argument is interpreted as hex.
* src/split.c (main): Just reset numeric_suffix_start,
and avoid reinterpretation validation.
* tests/split/numeric.sh: Adjust accordingly.
* NEWS: Mention the change in behavior.
This commit is contained in:
Pádraig Brady committed 2026-11-03 13:28:02 +00:00
1 parent a65907555f
commit 1704600adc
4 files changed
+28 -19

No files matched your search

+5
View File
@@ -246,6 +246,11 @@ GNU coreutils NEWS -*- outline -*-
whole width of a previous character, unless the --characters option is used.
This aligns with POSIX and terminal behavior.
'split' now uses the last specified -d,--numeric-suffixes, or
-x,--hex-suffixes option to set the suffix start value, resetting it to zero
if that option omits FROM. Previously, an omitted FROM retained any
previously specified start value.
'stty -g' now saves input and output speeds explicitly on systems
that store them separately from the control flags, such as BSD,
or on GNU/Linux with non-standard speeds.
+4
View File
@@ -3397,6 +3397,10 @@ minimum suffix length required is automatically determined.
@optItem{split,-x,}
@optItemx{split,--hex-suffixes,[=@var{from}]}
Like @option{--numeric-suffixes}, but use hexadecimal numbers (in lower case).
The starting value @var{from}, if specified, is also hexadecimal.
If hexadecimal or numeric suffix options are repeated, the last option
determines both the suffix type and the starting value, which defaults to zero
when @var{from} is omitted.
@optItem{split,--additional-suffix,=@var{suffix}}
Append an additional @var{suffix} to output file names. @var{suffix}
+1 -12
View File
@@ -1596,9 +1596,9 @@ main (int argc, char **argv)
/* Skip any leading zero. */
while (*optarg == '0' && *(optarg + 1) != '\0')
optarg++;
numeric_suffix_start = optarg;
}
}
numeric_suffix_start = optarg;
break;
case 'e':
@@ -1669,17 +1669,6 @@ main (int argc, char **argv)
usage (EXIT_FAILURE);
}
/* A start value given with --hex-suffixes may be invalid
for a later --numeric-suffixes. */
if (numeric_suffix_start
&& (strlen (numeric_suffix_start)
!= strspn (numeric_suffix_start, suffix_alphabet)))
{
error (0, 0, _("%s: invalid start value for numerical suffix"),
quote (numeric_suffix_start));
usage (EXIT_FAILURE);
}
/* Check that the suffix length is large enough for the numerical
suffix start value. */
if (numeric_suffix_start && strlen (numeric_suffix_start) > suffix_length)
+18 -7
View File
@@ -55,14 +55,25 @@ compare exp-0 x0f || fail=1
compare exp-1 x10 || fail=1
compare exp-2 x11 || fail=1
# A hexadecimal start value is invalid for a later --numeric-suffixes
returns_ 1 split --hex-suffixes=a --numeric-suffixes in 2> /dev/null || fail=1
# The last suffix option selects both the alphabet and the start value.
rm -f x?? || framework_failure_
split --hex-suffixes=a --numeric-suffixes=9 --lines=2 in || fail=1
compare exp-0 x09 || fail=1
compare exp-1 x10 || fail=1
rm -f x?? || framework_failure_
split --numeric-suffixes=20 --hex-suffixes=9 --lines=2 in || fail=1
compare exp-0 x09 || fail=1
compare exp-1 x0a || fail=1
# Only the final alphabet needs to accommodate the retained start value.
split --hex-suffixes=a -d -x --lines=2 in || fail=1
compare exp-0 x0a || fail=1
compare exp-1 x0b || fail=1
compare exp-2 x0c || fail=1
# Omitting FROM resets the start value to zero.
rm -f x?? || framework_failure_
split --hex-suffixes=a -d --lines=2 in || fail=1
compare exp-0 x00 || fail=1
# Omitting FROM resets the start value to zero, even in same base.
rm -f x?? || framework_failure_
split --numeric-suffixes=20 -d --lines=2 in || fail=1
compare exp-0 x00 || fail=1
# Interpret the start value as hex when determining the suffix length.
# 0x10 + 241 - 1 = 0x100, which requires three digits.