Commit 7f62652
committed
interp: handle bash >|, >>|, &>|, &>>|, <> redirects
The parser already recognises these tokens (RdrClob, AppClob,
RdrAllClob, AppAllClob, RdrInOut), but the runtime in
interp/runner.go only threaded RdrIn/RdrOut/AppOut/RdrAll/AppAll
through its three dispatch switches inside (*Runner).redir.
The remaining operators fell to the default branch and exited
with "unhandled redirect op", so any script using them failed
even though plain `>`/`>>` worked.
This shows up most often through templates that wrap user
commands in a `>|` to force-overwrite a known temp file (for
example, capturing $PWD across a persistent-shell invocation),
where the embedded interpreter's exit then propagates back to
the caller as a generic failure.
Treat the four "Clob" variants as identical to their plain
counterparts — they only differ from `>`/`>>`/`&>`/`&>>` in
that they bypass the noclobber shell option (set -C), and this
interpreter does not enforce noclobber on file redirects today.
RdrInOut (<>) opens the target with O_RDWR|O_CREATE and binds
it to the input fd; we plumb the result through stdinFile so
reads work. Writes back through fd 0 are not propagated since
stdin is exposed as io.Reader internally — sufficient for the
read-side use that accounts for nearly all real <> usage.
Adds four entries in the existing redirect table in
interp/interp_test.go covering >| (new file, overwrite) and
<> (read existing, create-if-missing).1 parent 9e7dd28 commit 7f62652
2 files changed
Lines changed: 40 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1469 | 1469 | | |
1470 | 1470 | | |
1471 | 1471 | | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
1472 | 1492 | | |
1473 | 1493 | | |
1474 | 1494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
998 | 998 | | |
999 | 999 | | |
1000 | 1000 | | |
1001 | | - | |
1002 | | - | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
1003 | 1014 | | |
1004 | 1015 | | |
1005 | 1016 | | |
| |||
1013 | 1024 | | |
1014 | 1025 | | |
1015 | 1026 | | |
1016 | | - | |
| 1027 | + | |
1017 | 1028 | | |
1018 | | - | |
| 1029 | + | |
1019 | 1030 | | |
| 1031 | + | |
| 1032 | + | |
1020 | 1033 | | |
1021 | 1034 | | |
1022 | 1035 | | |
1023 | 1036 | | |
1024 | 1037 | | |
1025 | 1038 | | |
1026 | | - | |
| 1039 | + | |
1027 | 1040 | | |
1028 | 1041 | | |
1029 | 1042 | | |
1030 | 1043 | | |
1031 | 1044 | | |
1032 | | - | |
| 1045 | + | |
1033 | 1046 | | |
1034 | | - | |
| 1047 | + | |
1035 | 1048 | | |
1036 | 1049 | | |
1037 | 1050 | | |
| |||
0 commit comments