Pipes & Redirection
The Jitzu shell supports Unix-style pipes and I/O redirection, plus a unique hybrid pipe system that lets you chain OS command output into Jitzu functions.
Unix Pipes
Use | to pass the output of one command as input to another.
When both sides are OS commands, the shell delegates to the system pipe:
> git log --oneline | head -5
a1b2c3d Add pattern matching
b2c3d4e Fix lexer edge case
c3d4e5f Refactor parser
d4e5f6a Add shell mode
e5f6a7b Initial commitHybrid Pipes
You can pipe OS command output into Jitzu pipe functions. The shell captures stdout from the left side and passes it as text to the Jitzu function on the right:
> git log --oneline | first
a1b2c3d Add pattern matching
> ls | grep("cs")
Parser.cs
Lexer.cs
Interpreter.cs
> git log --oneline | nth(2)
c3d4e5f Refactor parserAvailable Pipe Functions
| Function | Description |
|---|---|
first | First line of output |
last | Last line of output |
nth(n) | Nth line (0-indexed) |
grep(“pattern”) | Filter lines containing pattern |
head -n N | First N lines (default 10) |
tail -n N | Last N lines (default 10) |
sort [-r] | Sort lines alphabetically |
uniq | Remove consecutive duplicate lines |
wc [-l/-w/-c] | Count lines/words/chars |
tee [-a] file | Write to file and pass through |
more / less | View output in pager |
print | Print and pass through |
Pipe functions accept both Jitzu-style and shell-style argument syntax:
> ls | grep("test") // Jitzu-style parentheses
> ls | grep "test" // shell-style spacesChaining Pipe Functions
Pipe functions can be chained together:
> git log --oneline | grep("fix") | sort
a1b2c3d Fix login timeout
c3d4e5f Fix parser edge case
> ls *.cs | sort | tee filelist.txtBuiltin Pipes
Built-in commands can also be piped. Their output is captured and fed into the right side:
> diff file1.txt file2.txt | more
> cat server.log | grep("ERROR")
> find src -ext cs | sortOutput Redirection
Redirect command output to a file with > (overwrite) or >> (append).
ANSI color codes are automatically stripped from redirected output.
> echo "hello world" > greeting.txt
> echo "another line" >> greeting.txt
> ls *.cs > filelist.txt
> grep -rn "TODO" src/ > todos.txtInput Redirection
Use < to feed a file’s contents as stdin to a command:
> sort < names.txt
Alice
Bob
CharlieTee
The tee command writes its input to a file and also passes it through
to stdout, so you can save intermediate results in a pipeline:
> ls | tee filelist.txt
src/
tests/
Program.cs
> git log --oneline | tee -a log.txt | first
a1b2c3d Add pattern matchingUse -a to append instead of overwriting.
Command Chaining
Chain multiple commands together with logical operators:
| Operator | Behavior |
|---|---|
&& | Run next command only if the previous succeeded |
|| | Run next command only if the previous failed |
; | Run next command unconditionally |
> mkdir build && cd build
> echo hello > file.txt && cat file.txt
hello
> cd nonexistent || echo "directory not found"
directory not found
> echo step1 ; echo step2 ; echo step3
step1
step2
step3Background Execution
Append & to run a command in the background. See the Activity Monitor page for more on background job management.
> dotnet build &
[1] 12345
> jobs
[1] Running dotnet buildCall Operator
The & prefix (PowerShell-style call operator) forces a line to
be treated as an OS command instead of Jitzu code:
> & dotnet build