backticks: implement piping and std{in,out,err} redirection#61540
backticks: implement piping and std{in,out,err} redirection#61540StefanKarpinski wants to merge 1 commit intomasterfrom
Conversation
26f2b0e to
12a50f8
Compare
|
Converted to draft since it should not be merged until #61397 is (or not). |
|
Triage likes being able to use the syntax, but is unsure about the change to printing of pipeline objects, but may come around. The conservative approach here may be to revert the printing change part, merge that, and then open the printing change as its own, separate PR that we can decide later on if we want or not. |
|
The argument for printing as explicit |
b1546b3 to
1cae1de
Compare
53bead2 to
33b8361
Compare
Implement `|`, `<`, `>`, `>>`, `2>`, `2>>`, `1>`, and `0<` operators in backtick command literals. These lower to `pipeline()` calls at parse time, so `` `ls | sort > out.txt` `` works as expected. Fd-prefixed redirects (`2>`, `1>`, `0<`) require an unquoted integer before the operator — quoted integers like `'2'>file` are treated as regular arguments, matching POSIX shell behavior. The REPL shell mode is updated to handle pipeline/redirect commands, which previously failed with a `MethodError` on `length(::OrCmds)`. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
33b8361 to
ad10b28
Compare
Adds shell-style pipe and redirection operators to backtick command literals. Part of #20401. Examples:
Supported operators
cmd1 | cmd2cmd1to stdin ofcmd2cmd > filecmd >> filecmd < filecmd 2> filecmd 2>> filecmd 1> file>)cmd 0< file<)These lower to
pipeline()calls at parse time. Simple commands without operators still returnCmdas before.Display round-tripping
Pipeline and redirect objects display using backtick syntax when possible:
Commands with non-representable features (e.g. custom env,
setuid) fall back to the existingpipeline(...)display format.REPL shell mode
Shell mode now handles pipes and redirects. Before:
After:
In other words, previously shell mode would pass the
|as a literal argument to theechocommand; now it constructs a pipeline just asrun(`echo hello | wc -c`)would.Implementation notes
'|','>'), matching shell behavior'2'>fileredirects stdout with argument"2", not stderr (POSIX-compliant)$interpolationpipeline()call so stdout and stderr can have independent append modesThis PR was written with the assistance of generative AI.