bug-bash
[Top][All Lists]
Advanced

[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 11:18:05 +0200

On Thu, 2004-08-12 at 08:01, Paul Jarc wrote:
> Enrique Perez-Terron <address@hidden> wrote:
> > Now I suggest that 
> >
> >   cmd | exec
> >
> > be made syntactic sugar for
> >
> >   exec < <(cmd)
> 
> Why not just use the already-working syntax?

Because the already-working syntax is far more difficult to remember,
and far harder to read.

"exec< <()" is a 9-character string, all of which are syntax, including
the space which is required. In terms of human-brain memory items 'exec'
is one, and '()' is one, so there are five items to remember. Since the
last item is split by the intervening command there is the additional
possibility of forgetting the final parenthesis, to add clumsiness.

"|exec" is a five-character string all syntax. To the human brain,
"exec" is a single item, so "|exec" are two items to remember. 

The pipe operator is very frequently used, therefore easy to remember.
The process substitution is perhaps a newer invention in the history of
the shells, I have seen it used almost never in the 16 years I have
worked with Unix.

The syntax "exec </etc/profile" is not among the things I have seen most
often in scripts (other than my own), but for those who know it "exec |"
or "| exec" are logical extensions. The syntax with process substitution
suffers from the combined effect of two little known and little used
idioms, and I believe process substitution is even less known than
exec-redirection.

The process redirection syntax has an advantage in cases like

   exec < <(
      while ...; do
         100 lines of code
      done
   )

over

   while ...; do
      100 lines of code
   done | exec

because when you reach the end of the latter you are surprised, and must
re-interpret the last 100 lines of code in light of this surprise.

The process redirection also has an advantage when another file
descriptor than 0 or 1 is to be redirected. 

Otherwise the pipe syntax is much cleaner.

-Enrique





reply via email to

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