Skip to content

wolysh v0.5.0

Latest

Choose a tag to compare

@github-actions github-actions released this 06 Oct 09:13
· 1 commit to master since this release
46e6b58

wolysh v0.5.0: Bash compatibility

Wolysh 0.5.0 implements most of Bash's scripting language. Control flow,
[[ ]] and (( )), parameter expansion and arrays, redirections and process
substitution, strict mode and traps, and the Bash builtins scripts depend on
now behave as they do in Bash 5.3. The test suite runs each of these areas in
both shells and compares the results.

Highlights

#!/usr/bin/env wsh
set -euo pipefail
trap 'echo "failed at line $LINENO" >&2' ERR

declare -A sizes=()
while IFS= read -r -d '' file; do
    [[ $file =~ \.([a-z]+)$ ]] || continue
    (( sizes[${BASH_REMATCH[1]}] += $(stat -c %s "$file") ))
done < <(find src -type f -print0)

for ext in "${!sizes[@]}"; do
    case $ext in
        zig|py) printf '%-4s %8d bytes\n' "$ext" "${sizes[$ext]}" ;;
    esac
done
  • Control flow: if/elif/fi, case with ;& and ;;&, until,
    select, POSIX function definitions, local, time, [[ ]] (patterns,
    =~ with BASH_REMATCH, integer and file tests), (( )) and
    for (( init; test; step )).
  • Expansion: ${var:=}, ${var:?}, ${var#pat}, ${var/pat/rep},
    ${var:off:len}, case modification, ${!name}; indexed and associative
    arrays; declare/typeset attributes; Bash integer arithmetic in $(( )).
  • Redirection and quoting: exec redirections, {fd}>file, <>, >|,
    <( ) and >( ), $'...', extended globbing.
  • Strict mode: set -euo pipefail, PIPESTATUS, set -x with PS4, and
    traps for signals, EXIT, ERR, DEBUG and RETURN.
  • Builtins: Bash read, mapfile, getopts, printf (with %(fmt)T),
    type, command -v, hash, help, ulimit, pushd/popd/dirs, and
    more.
  • Interactive shell: UTF-8 editing with a kill ring, undo, bracketed paste
    and vi mode; history expansion; programmable completion; keyword
    highlighting; PS1 escapes and PROMPT_COMMAND.

Upgrading from 0.4

These changes can alter what existing wsh scripts do:

  • A bare word in a command argument stays literal: status=x; git status
    runs git status. Inside language expressions (if count > 10 {,
    print name) bare names still refer to variables.
  • name=value no longer exports the variable to child processes; use
    export or env NAME = value.
  • wsh -c 'cmd' a b sets $0 to a and $1 to b, as bash -c does.
  • read returns 1 at end of input.
  • An expansion error such as ${x:?message} stops a non-interactive shell with
    status 1.
  • Functions take precedence over builtins of the same name.
  • Native expression arithmetic rejects non-numeric operands instead of treating
    them as 0.
  • Scripts no longer print [1] pid for background jobs; interactive shells
    still do.

Known differences from Bash

  • $name on an indexed array expands to every element, as it does for wsh
    lists; Bash gives element 0. Use ${name[0]} in scripts meant for both
    shells, including for $BASH_REMATCH.
  • BASH_COMMAND is not set.
  • < and > in [[ ]] compare bytes rather than the locale's collation
    order.

Install or upgrade

Download wolysh-v0.5.0-linux-x86_64.tar.gz and its .sha256 file:

sha256sum -c wolysh-v0.5.0-linux-x86_64.tar.gz.sha256
tar -xzf wolysh-v0.5.0-linux-x86_64.tar.gz
mkdir -p "$HOME/.local/bin"
install -m 0755 wolysh-v0.5.0-linux-x86_64/wsh "$HOME/.local/bin/wsh"
"$HOME/.local/bin/wsh" --version

Ensure $HOME/.local/bin is on PATH. Source builds require Zig 0.16.0:

zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux -Dcpu=baseline

Verification

CI and the release workflow build for baseline x86_64, check that the tag
matches wsh --version, and run the unit, interactive and compatibility suites
before packaging. Most compatibility suites run each case in wsh and in Bash and
require the same output and exit status.

  • 337 unit tests
  • 37 interactive checks
  • 319 compatibility tests

Benchmarks were not re-measured for this release; the packaged results
describe v0.4.0.

Full changelog