Re: Environment and pipes

2015-09-14 Thread Jean Delvare
Le Friday 11 September 2015 à 20:23 +, Thorsten Glaser a écrit :
> Dixi quod…
> 
> >I think coprocesses are pretty usable for this in almost all cases
> >(I did have one where they weren’t, but you can still often background
> >a part, then play with fd redirection).
> 
> Another thing that may help you, if it’s absolutely needed:
> 
> Before we had ${PIPESTATUS[*]} I wrote things like this:
> 
> foo | (bar; echo $? >bar.rv) | baz
> 
> Similarily, you can do tricks with high file descriptors.
> 
> x=$( (echo foo | (tr a-z A-Z >&4) | (echo bla >&5)) 4>&1) 5>&1
> echo x=$x
> 
> This gives:
> 
> bla
> x=FOO

"Nice" :]

> Both not as efficient as direct variable assignment, but…
> 
> And let's not forget using…
>   while …; do …; done  … instead of…
>   cat foo | while …; do …; done
> … (which is cat abuse anyway).

Amen. I've been working with a lot of bash scripts and I yell each time
I see the "cat foo |" construct.

> Often, some not-so-basic or more modern scripting approaches
> can eliminate the need for a construct like you were asking for.

I will check with the customer. The example they provided was clearly
made up to illustrate the problem (and I do appreciate when customers
make the problem easy to understand) so I don't know exactly what their
actually script is doing.

-- 
Jean Delvare
SUSE L3 Support



Re: Environment and pipes

2015-09-14 Thread Thorsten Glaser
Jean Delvare dixit:

>I will check with the customer. The example they provided was clearly
>made up to illustrate the problem (and I do appreciate when customers
>make the problem easy to understand) so I don't know exactly what their
>actually script is doing.

Okay.

It’s probably better for all involved if actual script code
is worked on, but in this case, for a general inquiry, this
was good.

>Thanks for the hint. Customers are just starting to migrate, on our
>request (as it turns out that ksh-93 has a lot of bugs and upstream is
>hardly active so we did not feel like supporting it any more) and this
>is the first incompatibility I hear about.

I see.

>> Scripts can use this, e.g:
>>
>> # here, set +o foo is active
>> cat "$@" | while …; do set -o foo; …; done
>> # here, set +o foo is active again
>
>Sorry but I do not understand how this relate to the problem at hand?
>Just an illustration of another change in subshells that do not
>propagate to the main shell?

Yes, exactly. Since a few years, scripts may rely on this.
(Although the example is dated: functions defined with
“function” have function-local scope for shell options
since mksh R51, like recent ksh93 versions have.)

bye,
//mirabilos
-- 
„Cool, /usr/share/doc/mksh/examples/uhr.gz ist ja ein Grund,
mksh auf jedem System zu installieren.“
-- XTaran auf der OpenRheinRuhr, ganz begeistert
(EN: “[…]uhr.gz is a reason to install mksh on every system.”)