--- title: zash description: A small, fast POSIX shell for z/OS UNIX System Services, in the Almquist (ash) tradition. --- ## Why another shell The z/OS `/bin/sh` is dated, and the usual alternatives are bash and zsh. Those are comfortable interactively but slow as scripting shells, large, and encourage scripts that run nowhere else. On z/OS that cost is real: CPU time is billed, and every `fork()` copies an address space.
  1. 01

    spawn(), not fork()

    Children come from spawn(), so _BPX_SHAREAS can keep them in the same address space. Builtins cost no process at all, even in a pipeline or a command substitution.

  2. 02

    sh scripts, not a dialect

    Scripts written for zash run under the existing /bin/sh, dash, FreeBSD sh and bash. zash is the successor to IBM's KornShell-line /bin/sh, not a new language.

  3. 03

    ASCII or EBCDIC

    The character set is a compile-time choice and the source assumes neither. File tagging, STEPLIB and the z/OS shell behaviours scripts rely on are in scope.

  4. 04

    An interactive shell too

    Job control, tab completion, history, emacs and vi editing, with bash's key bindings. None of it is initialised by a non-interactive shell.

## How it compares CPU-seconds (user+sys, children included) from `make bench` / `bench/run.sh`. The benchmark scripts check each shell's output against the reference shell as well as timing it, so a wrong answer fails instead of merely being timed. ### z/OS Measured on z/OS (64-bit ASCII build, with the 64-bit C run-time in the dynamic LPA), against IBM's `/bin/sh` (`z/OS sh`), bash, zsh and oksh: | benchmark | zash | z/OS sh | bash | zsh | oksh | | --- | --- | --- | --- | --- | --- | | `$(builtin)` x 40000 | 0.04 | 20.63 | 22.44 | 51.34 | 36.49 | | `(( ))` as a command | 0.14 | n/a | 0.94 | 0.39 | n/a | | `[[ ]]` in a loop | 0.08 | 0.93 | 1.08 | 0.28 | n/a | | `[ ]` tests in a loop | 0.12 | 1.40 | 1.62 | 1.10 | n/a | | `case` dispatch | 0.06 | 0.64 | 0.78 | 0.35 | 0.59 | | small pipelines and `$(a \| b)` | 0.62 | 1.60 | 4.21 | 6.74 | 3.37 | | 2000 external commands | 0.49 | 0.52 | 1.55 | 2.87 | 1.39 | | subshells | 0.00 | 0.78 | 1.32 | 3.66 | 0.80 | | background jobs | 0.08 | 0.12 | 0.24 | 0.24 | 0.12 | | redirections | 0.26 | 0.35 | 0.32 | 0.32 | port bug | | here-documents | 0.31 | 1.09 | 0.72 | 1.03 | n/a | | `while read` over a file | 0.30 | 0.93 | 0.93 | 3.27 | port bug | | recursion | 0.04 | 0.24 | 0.28 | 0.22 | 0.20 | | `printf` | 1.19 | 1.92 | 1.40 | 1.40 | n/a | | `getopts` | 0.04 | 0.28 | 0.21 | 0.21 | n/a | | parameter trimming | 0.12 | 0.98 | 0.58 | 0.58 | n/a | | IFS field splitting | 0.04 | 0.32 | 0.05 | differs | n/a | | pattern matching and `case` | 0.27 | 3.04 | 0.98 | 0.98 | n/a | | count a log by level and hour | 0.17 | 0.54 | 1.20 | 1.20 | n/a | | render and check 100 configs | 0.16 | 0.20 | 0.62 | 0.62 | n/a | | file tagging and auto-conversion | 0.38 | 1.03 | 2.33 | 2.33 | n/a | The gap on z/OS is process creation: every command substitution, subshell and pipeline stage costs a full spawn or address-space copy in the other shells, whereas zash runs builtin command substitutions, output-only subshells and `echo`/`print` pipeline stages in-shell. `n/a` means the shell lacks the feature; `differs` means zsh did not field-split unquoted expansions; `port bug` reflects output corruption in the third-party `oksh` port. ### Linux x86-64 The same suite on Linux x86-64 via `make bench`, where `fork()` is cheap: | benchmark | zash | dash | bash | ksh93 | oksh | | --- | --- | --- | --- | --- | --- | | `$(builtin)` x 40000 | 0.01 | 8.20 | 17.99 | 0.11 | 25.24 | | function calls | 0.03 | 0.07 | 0.25 | 0.13 | 0.12 | | arithmetic loop | 0.07 | 0.19 | 0.53 | 0.24 | 0.31 | | `let` and integer variables | 0.10 | n/a | 0.78 | 0.35 | 0.43 | | `(( ))` as a command | 0.06 | n/a | 0.33 | 0.09 | 0.30 | | `[[ ]]` in a loop | 0.04 | n/a | 0.29 | 0.12 | n/a | | `[ ]` tests in a loop | 0.05 | 0.16 | 0.43 | 0.15 | 0.22 | | `case` dispatch | 0.03 | 0.07 | 0.20 | 0.09 | 0.14 | | small pipelines and `$(a \| b)` | 1.10 | 2.35 | 3.16 | 1.33 | 2.32 | | 2000 external commands | 0.55 | 0.53 | 0.81 | 0.56 | 0.84 | | subshells | 0.01 | 0.37 | 0.62 | 0.01 | 0.48 | | background jobs | 0.03 | 0.03 | 0.06 | 0.04 | 0.03 | | redirections | 0.07 | 0.08 | 0.11 | 0.09 | 5.85 | | here-documents | 0.03 | 0.03 | 0.08 | 0.10 | 0.13 | | `while read` over a file | 0.04 | 0.07 | 0.21 | 0.12 | 0.10 | | recursion | 0.02 | 0.04 | 0.17 | 0.05 | 0.06 | | `printf` | 0.09 | 0.12 | 0.23 | 0.16 | 19.70 | | `getopts` | 0.02 | 0.03 | 0.09 | 0.03 | 0.05 | | parameter trimming | 0.05 | 0.09 | 0.32 | 0.20 | 0.14 | | IFS field splitting | 0.03 | 0.04 | 0.11 | 0.05 | 0.06 | | pattern matching and `case` | 0.11 | 0.18 | 0.53 | 0.38 | 0.35 | | count a log by level and hour | 0.04 | 0.05 | 0.13 | 0.07 | 0.08 | | render and check 100 configs | 0.38 | 0.46 | 0.53 | 0.26 | 0.52 | See the [project README](https://github.com/skurtz97/zash#status) for the dynamic LPA notes and methodology. ## Get started ```sh git clone https://github.com/skurtz97/zash cd zash make # Linux: ./zash make check # run the suite ``` On z/OS, `make` builds the ASCII `./zash` with IBM Open XL C/C++ and `make zos-ebcdic` builds the EBCDIC variant. See [Building zash]({{< relref "docs/install" >}}) for the z/OS targets and the address-mode notes, and [Development]({{< relref "docs/develop" >}}) for what the test suite covers.