rakitzis / rc

rc shell -- independent re-implementation for Unix of the Plan 9 shell (from circa 1992)
Other
252 stars 23 forks source link

Inconsistency in output redirection #33

Closed CasperVector closed 7 years ago

CasperVector commented 7 years ago

As the title:

; ls 0 >[2=1] | sed 's/0/1/'
ls: 1: No such file or directory
; >[2=1] ls 0 | sed 's/0/1/'         
ls: 0: No such file or directory
CasperVector commented 7 years ago

As a side note, this seems to be consistent with the behaviour of plan9port rc, but I personally think the behaviour itself is incorrect.

rakitzis commented 7 years ago

I'd have to agree. Not looking at the source at the moment but it seems like an interesting bug. Presumably this is a feature of the grammar, the second redirection applies to the pipe as a whole. Not intuitive.

; {>[2=1] ls 0} | sed s/0/1/

is what you expect.

CasperVector commented 7 years ago

I also consider the grammar to be the root cause. I think it's worth modifying the grammar spec (if the modification is reasonably simple) to avoid this behaviour, even if that introduces yet another incompatibility to plan9port rc...

TobyGoodwin commented 7 years ago

It's a simple enough fix, just make the precedence of a prefix redir higher than pipe. d2a398257626faf73fd7a5326b31bbc3f613e3da Took me a little while to get there though... I've spent most of the last 10 years playing with PEGs and my CFG / LALR(1) / yacc skills are a little rusty! I don't have a Duff rc to hand, but I can confirm that the original rc grammar as published in the Tenth Edition manuals has the same too-low precedence for a prefix redirection.

CasperVector commented 7 years ago

Many thanks :)