Fork me on GitHub
Digital Commons

go-ruby-shellwords

Ruby's Shellwords split, escape & join in Go — MRI-compatible, .

MRI-compatibleshellsplitshellescapeshelljoinPOSIX shround-tripMRI byte-exact100% coverage6 arches
Documentation (MkDocs Material + mike) Go 1.26.4+ Coverage 100%
zsh
$ go get github.com/go-ruby-shellwords/shellwords@latest

go-ruby-shellwords is a pure-Go (no cgo) reimplementation of Ruby's Shellwords library — shellsplit, shellescape and shelljoin that match reference Ruby's behaviour byte-for-byte. It performs POSIX sh word splitting honouring single quotes, double quotes and backslash escapes, escapes a string so it survives one round of shell parsing, and joins an array of words back into a shell-safe command line — the inverse of splitting, with shellsplit(shelljoin(words)) == words guaranteed. An unmatched quote raises the same ArgumentError at the same point. It was extracted from rbgo's prelude/internals into a reusable standalone library: no dependency on the Ruby runtime, the dependency runs the other way. It is the Shellwords backend for go-embedded-ruby, bound by rbgo as a native module just like go-ruby-regexp and go-ruby-erb — differential-tested against MRI, 100% coverage, CI green across 6 arches and 3 OSes.

shellsplit ready

POSIX sh word splitting honouring single quotes, double quotes and backslash escapes, exactly as Ruby’s Shellwords.shellsplit does.

shellescape ready

Escaping a single string so it survives one round of shell parsing, byte-for-byte identical to MRI (including the empty-string '' case).

shelljoin ready

Joining an array of words into a single shell-safe command line, the inverse of shellsplit, matching reference Ruby.

Error on malformed input ready

An unmatched quote raises the same ArgumentError Ruby raises, at the same point in the input.

Round-trip fidelity ready

shellsplit(shelljoin(words)) == words over arbitrary words, the property reference Ruby guarantees.

Differential oracle & coverage ready

A wide word corpus split, escaped and joined both here and by the system ruby/shellwords, compared byte-for-byte; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

A faithful port of Ruby's Shellwords in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It splits, escapes and joins shell words the way reference Ruby does — POSIX sh quoting and backslash escapes, the empty-string '' case, the ArgumentError on an unmatched quote, and the shellsplit(shelljoin(words)) == words round-trip property. Validated differentially against the system ruby binary — split, escaped and joined output compared against shellwords. It is a standalone, reusable module extracted from rbgo's internals, and the Shellwords backend for the sibling org github.com/go-embedded-ruby.