Cametendo 8c6a2ab4c2 Add control flow, I/O redirection, functions, coreutils, history/completion
- I/O redirection: >, >>, <, 2>, 2>&1, &>
- Job control: background & operator
- if/elif/else/fi, for/do/done, while/until loops
- Shell functions with local/declare, positional param save/restore
- Exit code propagation via exitCodeErr sentinel
- Arithmetic expansion $((expr)) with bare variable names
- Command substitution $(cmd) with pipeline support
- Glob expansion, tilde expansion, ${VAR:-default} and other forms
- Tab completion and command history via chzyer/readline
- Inline comment stripping (# outside quotes)
- Builtins: test/[, read, printf, tr, sed, cut, tail, tee, xargs,
  basename, dirname, date, sleep, uniq, sort, wc, head, grep, find,
  true, false, break, continue, return, shift, set, unset, export,
  declare/local, source, alias, jobs, command, which, env
- Bug fixes: tokenizer parenDepth double-count for $((,
  splitPipe not paren-aware (broke pipelines in $()),
  local/declare TrimLeft stripping valid var name chars,
  parseBlocks missing nested keywords after do/then/else

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-26 12:50:06 +02:00
2026-05-26 10:00:45 +02:00

bash-for-windows

A fully functional bash shell for Windows, written in Go. Run bash commands and scripts natively on Windows without WSL, Cygwin, or MSYS2.

Features

  • Interactive shell with prompt (bash$)
  • Built-in commands: cd, pwd, echo, exit, export, source, alias, type
  • Built-in coreutils: ls, cat, grep, sort, wc, head, find, cp, mv, rm, mkdir, touch, clear
  • Command chaining: &&, ||, ;
  • Pipes: | between commands
  • Variable expansion: $NAME, ${NAME}
  • Variable assignment: NAME=VALUE command
  • Single & double quotes: 'literal', "$variable"
  • Script execution: bash-windows script.sh or -c 'commands'
  • No dependencies — single .exe file, runs on any Windows x86-64

Usage

bash-windows            # Interactive mode
bash-windows -c 'echo hello'
bash-windows script.sh

Examples

bash$ echo "Hello from bash-for-windows!"
bash$ ls -la
bash$ cd /tmp && pwd
bash$ cat file.txt | grep pattern | wc -l
bash$ name="Luffy" && echo $name
bash$ mkdir -p project/src && touch project/src/main.go

Building

Requires Go 1.21+.

# Linux
./build.sh

# Manual
go build -o build/bash-windows .

# Windows cross-compile
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o build/bash-windows.exe .

Project Structure

cmd/bash/        - Shell entry point
internal/shell/  - Shell engine (parser, executor, builtins, coreutils)
build/           - Compiled binaries

License

MIT

Description
Fully functional bash for windows
Readme MIT 154 KiB
Languages
Go 92.2%
PowerShell 6.6%
Shell 0.9%
Batchfile 0.3%