[Top][All Lists]

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

Re: Sub shell mit pipes

From: Enrique Perez-Terron
Subject: Re: Sub shell mit pipes
Date: Thu, 12 Aug 2004 05:27:30 +0200

On Thu, 2004-08-12 at 02:09, Chet Ramey wrote:
> Enrique Perez-Terron wrote:
> > In any case, the combinations < <(..) and > >(..)  should be implemented
> > using pipes and so be available on all architectures supporting pipes,
> > even if named pipes are not available. Is this the case already?
> No.  While these are common idioms, I have not been willing to invent
> syntax to encapsulate them.  What you're looking at is something like
> ksh coprocs, 

No! It has not been near my mind to have bidirectional communication
with a single subprocess!

I just commented on the fact that 

  od -c < <(grep root /etc/passwd)

is functionally equivalent to 

  grep root /etc/passwd | od -c

and therefore, the combination < <(..) can be implemented with a pipe
instead of a named pipe or using /dev/fd/%d.  By the way, the latter is
actually compatible with the use of unnamed pipes since

  int p[2];
  sprintf(buf, sizeof(buf), "/dev/fd/%d", p[0])
  cmd[arg_n] = buf;
  if (!fork()) {
    stdin = open(cmd[arg_n], O_RDONLY, 0);

effectively dup()s p[0].

The reason I ask if pipes are already used in this case it that the
manpage reminds us that some systems do not have named pipes or
/dev/fd/%d style device files. Using pipes would make the combination 
< <(..) available on such architectures even if <(..) per se is not.

The combination < <(..) is not really needed except in the cases where
the command outside the parenthesis must run in the main shell. This
happens when the command is 'exec'. Otherwise a pipe can be used
instead, ie. cmd2 | cmd1 can be used instead of cmd1 < <(cmd2). 

Now I suggest that 

  cmd | exec

be made syntactic sugar for

  exec < <(cmd)

provided that the combination < <(..) is implemented with pipes, so that
the translation works in all cases where the user expects the pipe to

One would still have to document the case as an exception to the job
control system, in the sense that cmd | exec works like
exec < <(cmd) with respect to job control.

Similarly for exec | cmd as syntactic sugar for exec > >(cmd).

> where Korn invented a syntax to specify them (|&) and
> added options to various builtins and created new redirection syntax
> to use them.
> I prefer the more general composition of basic features.
> Chet

reply via email to

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