Currently paste(1) silently does nothing if it's given no file
arguments:

    % printf 'hello\nworld\n'|paste
    %

I often do things like 'ps -p $(pgrep sh | paste -sd,)' and forget the
"-" argument. Some other systems (gnu coreutils, illumos, perhaps more)
default to reading from stdin if no files are given; I think that makes
sense, so diff to do that below.

Index: paste.c
===================================================================
RCS file: /cvs/src/usr.bin/paste/paste.c,v
retrieving revision 1.22
diff -u -p -r1.22 paste.c
--- paste.c     9 Dec 2015 19:39:10 -0000       1.22
+++ paste.c     29 Dec 2017 13:47:50 -0000
@@ -56,6 +56,7 @@ main(int argc, char *argv[])
        extern char *optarg;
        extern int optind;
        int ch, seq;
+       char **files = (char *[]){ "-", NULL };
 
        if (pledge("stdio rpath", NULL) == -1)
                err(1, "pledge");
@@ -77,15 +78,18 @@ main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
+       if (argc)
+               files = argv;
+
        if (!delim) {
                delimcnt = 1;
                delim = "\t";
        }
 
        if (seq)
-               sequential(argv);
+               sequential(files);
        else
-               parallel(argv);
+               parallel(files);
        exit(0);
 }
 
-- 
Lauri Tirkkonen | lotheac @ IRCnet

Reply via email to