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.
---
NEWS | 5 +++++
doc/coreutils.texi | 4 ++++
src/split.c | 13 +------------
tests/split/numeric.sh | 27 +++++++++++++++++++--------
4 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/NEWS b/NEWS
index 6fddbaaa3..2ae5b8301 100644
--- a/NEWS
+++ b/NEWS
@@ -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.
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index cb1f9ee6c..2c08a1fe6 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -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}
diff --git a/src/split.c b/src/split.c
index ec9160114..da30b109d 100644
--- a/src/split.c
+++ b/src/split.c
@@ -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)
diff --git a/tests/split/numeric.sh b/tests/split/numeric.sh
index 204ab98e5..cfe6bd8d2 100755
--- a/tests/split/numeric.sh
+++ b/tests/split/numeric.sh
@@ -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
-
-# 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
+# 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
+
+# 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.
--
2.56.0