From: Pádraig Brady Date: Fri, 13 Mar 2026 11:05:40 +0000 (+0000) Subject: cut: support -O as an alias for --output-delimiter X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77ccacb9a7fc29481cda9ae558d47de7ddce1aed;p=thirdparty%2Fcoreutils.git cut: support -O as an alias for --output-delimiter 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. --- diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 3b02f70bf5..00244655ba 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -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 diff --git a/src/cut.c b/src/cut.c index 507d1ba074..bfa8305f52 100644 --- 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' diff --git a/tests/cut/cut.pl b/tests/cut/cut.pl index 905e84c548..893386a7fe 100755 --- a/tests/cut/cut.pl +++ b/tests/cut/cut.pl @@ -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