]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tee: treat '-' operand as file name as mandated by POSIX
authorBernhard Voelker <mail@bernhard-voelker.de>
Fri, 20 Feb 2015 07:10:51 +0000 (08:10 +0100)
committerBernhard Voelker <mail@bernhard-voelker.de>
Fri, 20 Feb 2015 13:00:41 +0000 (14:00 +0100)
Since v5.2.1-1247-g8dafbe5, tee(1) treated '-' as stdout while POSIX
explicitly requires to treat this as a file name.  Revert this change,
as the interleaved output - due to sending another copy of input to
stdout - is not considered to be useful.  Discussed in
http://lists.gnu.org/archive/html/coreutils/2015-02/msg00085.html

* src/tee.c (tee_files): Remove the special handling for "-" operands.
(usage): Remove the corresponding sentence.
* doc/coreutils.texi (common options): Remove the "tee -" example.
(tee invocation): Document that tee(1) now treats "-" as a file name.
* tests/misc/tee.sh: Add a test case for "tee -".
While at it, re-indent the above multi-argument processing case and
extend that to 13 operands, as POSIX mandates that, too.
* tests/misc/tee-dash.sh: Remove now-obsolete test.
* tests/local.mk (all_tests): Remove the above test.
* NEWS (Changes in behavior): Mention the change.

NEWS
doc/coreutils.texi
src/tee.c
tests/local.mk
tests/misc/tee-dash.sh [deleted file]
tests/misc/tee.sh

diff --git a/NEWS b/NEWS
index b6795aacf720f948c3eab51309965298918073f9..859735743118b92a3544dc4261141ca3346892e0 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,10 @@ GNU coreutils NEWS                                    -*- outline -*-
 
   tee will exit early if there are no more writable outputs.
 
+  tee does not treat the file operand '-' as meaning standard output any longer,
+  for better conformance to POSIX.  This feature was added in coreutils-5.3.0.
+
+
 ** Improvements
 
   cp,install,mv will convert smaller runs of NULs in the input to holes,
index bb652aca5ff2b2c268cc78f3b2efa50b383c0adf..8d050c2e8f588c33de6716235fc9a92e7c519efe 100644 (file)
@@ -752,11 +752,10 @@ operands even if they begin with @samp{-}.  For example, @samp{sort --
 @cindex standard input
 @cindex standard output
 A single @samp{-} operand is not really an option, though it looks like one.  It
-stands for standard input, or for standard output if that is clear from
-the context.  For example, @samp{sort -} reads from standard input,
-and is equivalent to plain @samp{sort}, and @samp{tee -} writes an
-extra copy of its input to standard output.  Unless otherwise
-specified, @samp{-} can appear as any operand that requires a file
+stands for a file operand, and some tools treat it as standard input, or as
+standard output if that is clear from the context.  For example, @samp{sort -}
+reads from standard input, and is equivalent to plain @samp{sort}.  Unless
+otherwise specified, a @samp{-} can appear as any operand that requires a file
 name.
 
 @menu
@@ -13180,9 +13179,11 @@ If a file being written to does not already exist, it is created.  If a
 file being written to already exists, the data it previously contained
 is overwritten unless the @option{-a} option is used.
 
-A @var{file} of @samp{-} causes @command{tee} to send another copy of
-input to standard output, but this is typically not that useful as the
-copies are interleaved.
+In previous versions of GNU coreutils (v5.3.0 - v8.23), a @var{file} of @samp{-}
+caused @command{tee} to send another copy of input to standard output.
+However, as the interleaved output was not very useful, @command{tee} now
+conforms to POSIX which explicitly mandates it to treat @samp{-} as a file
+with such name.
 
 The program accepts the following options.  Also see @ref{Common options}.
 
index bfe1b6900f815d0efd0d94bae9d840b83e2ea4bd..feb4026286f3727f260c1ceacaaf2d5ee37227aa 100644 (file)
--- a/src/tee.c
+++ b/src/tee.c
@@ -68,10 +68,6 @@ Copy standard input to each FILE, and also to standard output.\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
       fputs (VERSION_OPTION_DESCRIPTION, stdout);
-      fputs (_("\
-\n\
-If a FILE is -, copy again to standard output.\n\
-"), stdout);
       emit_ancillary_info (PROGRAM_NAME);
     }
   exit (status);
@@ -169,9 +165,8 @@ tee_files (int nfiles, const char **files)
 
   for (i = 1; i <= nfiles; i++)
     {
-      descriptors[i] = (STREQ (files[i], "-")
-                        ? stdout
-                        : fopen (files[i], mode_string));
+      /* Do not treat "-" specially - as mandated by POSIX.  */
+      descriptors[i] = fopen (files[i], mode_string);
       if (descriptors[i] == NULL)
         {
           error (0, errno, "%s", files[i]);
index 53c7c83e079121f563bbe1e47e18504c99b5fc64..9a5208082e2a9c1f332ef2090c91d857f9c61e8f 100644 (file)
@@ -382,7 +382,6 @@ all_tests =                                 \
   tests/misc/tac-2-nonseekable.sh              \
   tests/misc/tail.pl                           \
   tests/misc/tee.sh                            \
-  tests/misc/tee-dash.sh                       \
   tests/misc/test-diag.pl                      \
   tests/misc/timeout.sh                                \
   tests/misc/timeout-blocked.pl                        \
diff --git a/tests/misc/tee-dash.sh b/tests/misc/tee-dash.sh
deleted file mode 100755 (executable)
index 1063211..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-# test for "tee -".
-
-# Copyright (C) 2005-2015 Free Software Foundation, Inc.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-print_ver_ tee
-
-tee - </dev/null || fail=1
-
-Exit $fail
index 5f2eeda7b210c49d98d008a6576d64aa11688055..ecca6562bf74bdaef76ee6aebf099eff1f64e5c0 100755 (executable)
 print_ver_ tee
 
 echo line >sample || framework_failure_
-nums=$(seq 9) || framework_failure_
-
-for n in 0 $nums; do
-        files=$(seq $n)
-        rm -f $files
-        tee $files <sample >out || fail=1
-        for f in out $files; do
-                compare sample $f || fail=1
-        done
+
+# POSIX says: "Processing of at least 13 file operands shall be supported."
+for n in 0 1 2 12 13; do
+  files=$(seq $n)
+  rm -f $files
+  tee $files <sample >out || fail=1
+  for f in out $files; do
+    compare sample $f || fail=1
+  done
 done
 
+# Ensure tee treats '-' as the name of a file, as mandated by POSIX.
+# Between v5.3.0 and v8.23, a '-' argument caused tee to send another
+# copy of input to standard output.
+tee - <sample >out 2>err || fail=1
+compare sample ./- || fail=1
+compare sample out || fail=1
+compare /dev/null err || fail
 
 # Ensure tee exits early if no more writable outputs
 if test -w /dev/full && test -c /dev/full; then