bug-textutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple inputs / outputs through descriptors


From: Bob Proulx
Subject: Re: multiple inputs / outputs through descriptors
Date: Sat, 30 Aug 2003 21:14:54 -0600
User-agent: Mutt/1.3.28i

address@hidden wrote:
>   Since I didn't find textutils / coreutils discussion list
> (only coreutils-announce), and this is more of a technical
> implementation / feature issue, I'm writing this into
> bug-textutils. Please forward / repost where appropriate or
> let me know.

You have sent your note go a reasonable place.  But for the future
here is the documentation you were looking for.

  http://www.gnu.org/software/coreutils/

>   Standardize throughout GNU utils (just like long options 
> have been standardized) a descriptor input / output syntax. 

In the old days '-' was considered the standard for stdin and stdout.
Look at 'tar' for one example.  (e.g. 'gunzip file.tar.gz | tar tvf -')
But that is "in-band control" and creates the possibility of name
conflicts.

> e.g. I could write (in bash) something like this :
> 
>  ( process1 --output 3>&1 ; process2 --output 4>&1 ) | diff --input-file %3% 
> --input-file %4%

Yes, that is ugly.  How about using bash's process substitution?

   Process Substitution
       Process  substitution is supported on systems that support
       named pipes (FIFOs) or the /dev/fd method of  naming  open
       files.  It takes the form of <(list) or >(list).  The pro-
       cess list is run with its input or output connected  to  a
       FIFO  or  some  file in /dev/fd.  The name of this file is
       passed as an argument to the current command as the result
       of the expansion.  If the >(list) form is used, writing to
       the file will provide input for list.  If the <(list) form
       is  used, the file passed as an argument should be read to
       obtain the output of list.

Then your above example looks like this.  This looks much cleaner to
me.

  diff <(process1) <(process2)

Here is a real example you can try.

  diff -u <(printf "foo\nbar\n") <(printf "baz\nbar\n")

  --- /tmp/sh-np-a20909   Sat Aug 30 20:59:55 2003
  +++ /tmp/sh-np-b20909   Sat Aug 30 20:59:55 2003
  @@ -1,2 +1,2 @@
  -foo
  +baz
   bar

This works even on my ancient HP-UX 10.20 machine upon which I tested
this example.  As long as the system supports named pipes this is
available.  Newer systems with /dev/fd are even better.  But I don't
believe this is specified by POSIX and so should be considered a bash
only feature.  But I say that not knowing if other shells support it
or not.  Just that it is not a POSIX /bin/sh feature.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]