Repository navigation
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,casewith;∧;&,until,
select, POSIX function definitions,local,time,[[ ]](patterns,
=~withBASH_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/typesetattributes; Bash integer arithmetic in$(( )). - Redirection and quoting:
execredirections,{fd}>file,<>,>|,
<( )and>( ),$'...', extended globbing. - Strict mode:
set -euo pipefail,PIPESTATUS,set -xwithPS4, and
traps for signals,EXIT,ERR,DEBUGandRETURN. - 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;PS1escapes andPROMPT_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
runsgit status. Inside language expressions (if count > 10 {,
print name) bare names still refer to variables. name=valueno longer exports the variable to child processes; use
exportorenv NAME = value.wsh -c 'cmd' a bsets$0toaand$1tob, asbash -cdoes.readreturns 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] pidfor background jobs; interactive shells
still do.
Known differences from Bash
$nameon 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_COMMANDis 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" --versionEnsure $HOME/.local/bin is on PATH. Source builds require Zig 0.16.0:
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux -Dcpu=baselineVerification
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.