]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cut: support -O as an alias for --output-delimiter
authorPádraig Brady <P@draigBrady.com>
Fri, 13 Mar 2026 11:05:40 +0000 (11:05 +0000)
committerPádraig Brady <P@draigBrady.com>
Sun, 5 Apr 2026 12:15:56 +0000 (13:15 +0100)
To improve compatibility with toybox/busybox scripts.

* doc/coreutils.texi (cut invocation): Add -O description.
* src/cut.c: Support -O as well as --output-delimiter
* tests/cut/cut.pl: Adjust one case to use -O.

doc/coreutils.texi
src/cut.c
tests/cut/cut.pl

index 3b02f70bf59cccff7d660da04a29287d22d79f3b..00244655bafc9c7100c038edb8d725e51cde0e85 100644 (file)
@@ -6224,7 +6224,8 @@ for it to be selected.
 For @option{-f}, do not print lines that do not contain the field separator
 character.  Normally, any line without a field separator is printed verbatim.
 
-@optItem{cut,--output-delimiter,=@var{string}}
+@optItem{cut,-O,@w{ }@var{string}}
+@optItemx{cut,--output-delimiter,=@var{string}}
 With @option{-f}, output fields are separated by @var{string}.
 The default with @option{-f} is to use the input delimiter.
 When using @option{-b} or @option{-c} to select ranges of byte or
index 507d1ba0747a9b2e71d63370ba14ef6370304a9a..bfa8305f52cce44a758a49ed7ec65e3f75e9a7c4 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -128,8 +128,7 @@ static enum
    non-character as a pseudo short option, starting with CHAR_MAX + 1.  */
 enum
 {
-  OUTPUT_DELIMITER_OPTION = CHAR_MAX + 1,
-  COMPLEMENT_OPTION
+  COMPLEMENT_OPTION = CHAR_MAX + 1
 };
 
 static struct option const longopts[] =
@@ -141,7 +140,7 @@ static struct option const longopts[] =
   {"no-partial", no_argument, NULL, 'n'},
   {"whitespace-delimited", no_argument, NULL, 'w'},
   {"only-delimited", no_argument, NULL, 's'},
-  {"output-delimiter", required_argument, NULL, OUTPUT_DELIMITER_OPTION},
+  {"output-delimiter", required_argument, NULL, 'O'},
   {"complement", no_argument, NULL, COMPLEMENT_OPTION},
   {"zero-terminated", no_argument, NULL, 'z'},
   {GETOPT_HELP_OPTION_DECL},
@@ -193,13 +192,13 @@ Print selected parts of lines from each FILE to standard output.\n\
          with -b, don't output partial multi-byte characters\n\
 "));
       oputs (_("\
-  -s, --only-delimited\n\
-         do not print lines not containing delimiters\n\
-"));
-      oputs (_("\
-      --output-delimiter=STRING\n\
+  -O, --output-delimiter=STRING\n\
          use STRING as the output delimiter;\n\
          the default is to use the input delimiter\n\
+"));
+      oputs (_("\
+  -s, --only-delimited\n\
+         do not print lines not containing delimiters\n\
 "));
       oputs (_("\
   -w, --whitespace-delimited\n\
@@ -896,7 +895,7 @@ main (int argc, char **argv)
 
   atexit (close_stdout);
 
-  while ((optc = getopt_long (argc, argv, "b:c:d:f:nszw", longopts, NULL))
+  while ((optc = getopt_long (argc, argv, "b:c:d:f:nO:szw", longopts, NULL))
          != -1)
     {
       switch (optc)
@@ -951,7 +950,7 @@ main (int argc, char **argv)
           whitespace_delimited = true;
           break;
 
-        case OUTPUT_DELIMITER_OPTION:
+        case 'O':
           /* Interpret --output-delimiter='' to mean
              'use the NUL byte as the delimiter.'  */
           output_delimiter_length = (optarg[0] == '\0'
index 905e84c548d5f3f57c4ed99d8abfa2892a35f18c..893386a7feab5bcfd9a375715d2da1631e285e1d 100755 (executable)
@@ -123,8 +123,7 @@ my @Tests =
   ['o-delim', qw(-d: --out=_), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b_c\n"}],
   ['nul-idelim', qw(-d '' --out=_), '-f2,3', {IN=>"a\0b\0c\n"}, {OUT=>"b_c\n"}],
   ['nul-odelim', qw(-d: --out=), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b\0c\n"}],
-  ['multichar-od', qw(-d: --out=_._), '-f2,3', {IN=>"a:b:c\n"},
-   {OUT=>"b_._c\n"}],
+  ['multichar-od', qw(-d: -O _._), '-f2,3', {IN=>"a:b:c\n"}, {OUT=>"b_._c\n"}],
 
   # Ensure delim is not allowed without a field
   # Prior to 8.21, a NUL delim was allowed without a field