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:

Shell
> git log --oneline | head -5
a1b2c3d Add pattern matching
b2c3d4e Fix lexer edge case
c3d4e5f Refactor parser
d4e5f6a Add shell mode
e5f6a7b Initial commit

Hybrid 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:

Shell
> git log --oneline | first
a1b2c3d Add pattern matching

> ls | grep("cs")
Parser.cs
Lexer.cs
Interpreter.cs

> git log --oneline | nth(2)
c3d4e5f Refactor parser

Available Pipe Functions

FunctionDescription
firstFirst line of output
lastLast line of output
nth(n)Nth line (0-indexed)
grep(“pattern”)Filter lines containing pattern
head -n NFirst N lines (default 10)
tail -n NLast N lines (default 10)
sort [-r]Sort lines alphabetically
uniqRemove consecutive duplicate lines
wc [-l/-w/-c]Count lines/words/chars
tee [-a] fileWrite to file and pass through
more / lessView output in pager
printPrint and pass through

Pipe functions accept both Jitzu-style and shell-style argument syntax:

Shell
> ls | grep("test") // Jitzu-style parentheses
> ls | grep "test" // shell-style spaces

Chaining Pipe Functions

Pipe functions can be chained together:

Shell
> git log --oneline | grep("fix") | sort
a1b2c3d Fix login timeout
c3d4e5f Fix parser edge case

> ls *.cs | sort | tee filelist.txt

Builtin Pipes

Built-in commands can also be piped. Their output is captured and fed into the right side:

Shell
> diff file1.txt file2.txt | more
> cat server.log | grep("ERROR")
> find src -ext cs | sort

Output Redirection

Redirect command output to a file with > (overwrite) or >> (append). ANSI color codes are automatically stripped from redirected output.

Shell
> echo "hello world" > greeting.txt
> echo "another line" >> greeting.txt

> ls *.cs > filelist.txt

> grep -rn "TODO" src/ > todos.txt

Input Redirection

Use < to feed a file’s contents as stdin to a command:

Shell
> sort < names.txt
Alice
Bob
Charlie

Tee

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:

Shell
> ls | tee filelist.txt
src/
tests/
Program.cs

> git log --oneline | tee -a log.txt | first
a1b2c3d Add pattern matching

Use -a to append instead of overwriting.

Command Chaining

Chain multiple commands together with logical operators:

OperatorBehavior
&&Run next command only if the previous succeeded
||Run next command only if the previous failed
;Run next command unconditionally
Shell
> 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
step3

Background Execution

Append & to run a command in the background. See the Activity Monitor page for more on background job management.

Shell
> dotnet build &
[1] 12345

> jobs
[1]  Running    dotnet build

Call Operator

The & prefix (PowerShell-style call operator) forces a line to be treated as an OS command instead of Jitzu code:

Shell
> & dotnet build