Martijn Dekker dixit:

>Op 22-03-17 om 10:12 schreef Jean Delvare:
>> Concretely, the customer's code looks like this:
>>
>> command | while read line
>> do
>>      if <condition>
>>      then
>>              exit
>>      fi
>>      process $line
>> done
>[...]
>> I was wondering if there is any other trick you can suggest that would work 
>> in mksh?
>
>A here-string with a command substitution:

That works but if not very performant.

This is actually a FAQ ;-) Use co-processes!

command |& while read -p line; do …


Dr. Werner Fink dixit:

>Just to be mentioned, I can mksh change in such a way that without job control
>I can do
>
>   ~/rpmbuild/BUILD/mksh> ./mksh -c 'echo xxx | read yyy; echo $yyy'
>   xxx
>
>that is it does work similar to the lastpipe shell option of the bash
>I had initiated now 7 years back. The trick is to avouid forking the
>last element in a pipe chain.

I’ve thought about this… years ago, too. But seeing as POSIX allows
either behaviour, I decided that this (running all sides of pipelines
in subshells) is a language feature now, for simplicity of user scripts
(as they can just use co-processes when they don’t want it).

So, thanks but no. (I’ve got scripts that actually rely on that now.)

bye,
//mirabilos
-- 
Solange man keine schmutzigen Tricks macht, und ich meine *wirklich*
schmutzige Tricks, wie bei einer doppelt verketteten Liste beide
Pointer XORen und in nur einem Word speichern, funktioniert Boehm ganz
hervorragend.           -- Andreas Bogk über boehm-gc in d.a.s.r

Reply via email to