Re: A note for read builtin

2010-06-17 Thread Marc Herbert
Le 16/06/2010 19:03, Greg Wooledge a écrit :
> On Wed, Jun 16, 2010 at 07:47:03PM +0200, Krzysztof ??elechowski wrote:
>> The description of the read builtin [19] would benefit of the following note:
>> Warning: A pipeline of the form { echo 1 2 | read a b; } is not useful.  Use 
>> { 
>> read<<<"1 2" a b; } instead.

> That kind of advice is certainly welcome in tutorials, guides, and so on
> which are teaching shell programming.  I don't really think it needs to
> go into the manual, though.  There are hundreds, if not thousands, of
> things you should _not_ do, that shouldn't have to be stated in the
> reference manual.  This is just one of them.

- I do not think this is "just one of them". This question
  pops up VERY regularly here, many times more than other
  things that should not be done.

- Consider the very first sentence in the documentation:
  


 read
  One line is read from the standard input, or from...

  Such a description obviously begs for a pipeline; no surprise everyone
  makes this mistake one day or the other.

- The POSIX standard does allow "echo 1 2 | read a b" to be useful
  (cf. 2.12 "Shell Execution Environment"). Some alternatives to
  bash actually make it useful. Standard and portability concerns
  definitely belong to a reference manual.





Re: A note for read builtin

2010-06-17 Thread Roman Rakus

On 06/17/2010 10:28 AM, Marc Herbert wrote:

- The POSIX standard does allow "echo 1 2 | read a b" to be useful
   (cf. 2.12 "Shell Execution Environment"). Some alternatives to
   bash actually make it useful. Standard and portability concerns
   definitely belong to a reference manual.

   
Maybe the POSIX expect shell to execute the last command of pipeline not 
in subshell. Bash executes all commands of pipeline in subshell. Ksh 
executes all but not the last in subshell. I don't how behave other shells.


RR



Re: A note for read builtin

2010-06-17 Thread Marc Herbert
>> - The POSIX standard does allow "echo 1 2 | read a b" to be useful
>>(cf. 2.12 "Shell Execution Environment"). 
   
> Maybe the POSIX expect shell to execute the last command of pipeline
> not in subshell.

>From section 2.12 and from messages posted here in the past I
understand that POSIX allows either one. This ambiguity reinforces the
need for documentation IMHO.




Re: A note for read builtin

2010-06-17 Thread Jan Schampera

Marc Herbert schrieb:


From section 2.12 and from messages posted here in the past I
understand that POSIX allows either one. This ambiguity reinforces the
need for documentation IMHO.


I agree with Greg here, it's a well known "don't". What should be 
documented is (maybe it is?) how pipelines are implemented in general, 
the behaviour of read is just a plain consequence of that.


Infact I mean that reading a reference manual doesn't avoid learning a 
language and its behaviours.


just my 2ct
Jan