Stefan Monnier (12024-06-21):
> And if it's not a tty, you get some kind of Undefined Behavior?

Knowing that “undefined behavior” is just an expression invented by C
standards authors to make “we make no guarantee about it, use it at your
own risk” sound more scary, I do not think it is a severe problem.

> I don't think I'd like that because I don't think the benefit would be worth
> the UB troubles.

The reasoning is the other way around: this feature should not be used,
and therefore the trouble of standardizing it is a waste of time.

The reason this feature should not be used is that it is exceptional. It
does not work with scripting languages that read their whole script
before running. It does not work with chained commands: “(head -n 2 >
/tmp/1 ; head -n 4 > /tmp/2)” will not put the next four lines in the
/tmp/2 file. None of the standard shell utilities makes any effort to
control buffering, and doing so would either change their semantics or
ruin their performances. Only the shell itself has this constraint.

So in order to use this guarantee properly, you need to be absolutely
sure you are in the exact case it covers. And odds are you will realize
it does not work because you added something in between that does
buffering.

Better just design your script in a way that does not rely on buffering
subtleties.

Regards,

-- 
  Nicolas George

Reply via email to