1. Introduction

A command line written as one string is common in configuration and tooling. npm scripts, editor task definitions, test-runner options, CI steps, Makefile-like recipes and the tool-call arguments of coding agents all store commands as text. Running such a string through sh -c hands the whole POSIX shell language to the string, with expansions, operators and command substitution, so many programs instead split the string into words with a library and call execve directly. The opposite step is just as common: a program builds an argument vector and quotes it into a single string that some shell will later read, for example over ssh, inside docker exec, or in a generated script.

Both steps make a claim about a shell. A splitter claims that its output is the argument vector a POSIX shell would produce for the same text, at least for the subset it supports. A quoter claims that a shell will read its output back as exactly the original string. These claims are rarely checked against a real shell. Each library has its own unit tests, written from its authors’ reading of the POSIX Shell Command Language [1]. Those readings differ in places the specification does fix: which characters a backslash escapes inside double quotes, whether backslash-newline disappears, which characters separate words, and what happens to an unterminated quote.

This paper measures those differences directly. We use dash, the default /bin/sh on Debian and Ubuntu, as the reference, and check every case against bash --posix as well. Each case string is passed as the arguments of a shell function, and the function records the argument vector it received. This turns the shell into an oracle for word splitting and quote removal. It is a differential test in McKeeman’s sense [2] with a real implementation as the reference, rather than a comparison between libraries that might share the same mistake.

Our contributions are:

  • a case list of 87 strings in ten groups, with dash’s and bash’s readings for each, of which 63 are scored against the libraries;
  • a verdict matrix for ten splitters in four languages and a round-trip check for eight quoting functions, in both shells with globbing on;
  • a sample of 1,402 real npm scripts strings that shows how often the measured differences matter in practice and how often the strings need a shell at all;
  • a reproducible package pinned at one commit, which re-runs the matrix in seconds and gave byte-identical output on two runs and on a clean export.

Formal and static treatments of the shell. Smoosh gives an executable formal semantics of the POSIX shell and tests it against several shells, including dash and bash, with the POSIX test suite and its own tests [3]. Morbig is a static parser for POSIX shell scripts that handles the grammar’s context-sensitive parts and was used to parse all maintainer scripts in Debian [4]. Greenberg argues that word expansion, rather than control flow, is the core of what the shell does and studies it in isolation [5]. These works model the shell itself. They do not ask whether the many small libraries that approximate one step of the shell, splitting a string into words, agree with it. PaSh parallelises shell scripts and relies on a precise model of shell expansion to do so safely [6]; its focus is performance, not library fidelity.

Library test suites. CPython’s Lib/test/test_shlex.py [7], go-shellwords’ shellwords_test.go [8] and the shell-quote, shlex and shell-words crates’ tests each check one library against its authors’ expectations. None of them runs a shell. We found no published cross-library comparison of shell word splitters, and no comparison of quoting functions by round trip through a real shell.

Quoting defects in practice. CVE-2021-42740 was a command-injection defect in shell-quote’s quote (versions 1.6.3 to 1.7.2), where a character class written [A-z] let backticks through unescaped [9]. Our quote check is the kind of test that would catch such a defect mechanically: a quoted form that a shell does not read back as the original string fails, whatever the reason.

Differential testing of formats. Our harness follows the differential style used for HTTP header parsing, where the same inputs are sent to many implementations and each outcome is classed against a written reading [12]. Here the reading is not prose but a running shell, which removes one source of interpretation error.

3. Method

Subjects (default options, public APIs). CPython 3.13.5: (1) shlex.split from the standard library, which uses POSIX mode and, by default, does not treat # as a comment. Node.js v24.22.1: (2) shell-quote 1.12.0 parse, (3) string-argv 0.4.0 parseArgsStringToArgv, (4) shlex 3.0.1 split. Go 1.27.3: (5) google/shlex (pseudo-version v0.0.0-20191202100458-e7afc7fbc510) Split, (6) kballard/go-shellquote (v0.0.0-20180428030007-95032a82bc51) Split, (7) mattn/go-shellwords 1.0.17 Parse, (8) mvdan.cc/sh/v3 3.14.1 shell.Fields, which parses the string with mvdan/sh’s shell parser and expands it with an environment that holds only HOME and PATH, matching the reference. Rust 1.85.1: (9) shlex 1.3.0 split, (10) shell-words 1.1.0 split. The quoting functions are shell-quote quote, shell-escape 0.2.0, npm shlex quote, Python shlex.quote, go-shellquote Join, mvdan/sh syntax.Quote(s, LangPOSIX), Rust shlex try_quote and shell-words quote. We also tried yargs-parser, whose string tokenizer is often used for this purpose, but dropped it: the tokenizer is not exported, and it leaves quotes in tokens for a later stage of option parsing, so its raw output is not an argument vector.

Where a library returns markers for shell syntax, the runner keeps them visible. shell-quote returns objects for operators, comments and globs; these are written as <op:…>, <comment:…> and the glob pattern, so a marker never silently matches a word. Any exception or error value is recorded with its message.

Reference. oracle.py runs each case s as f s in a shell, where f writes each of its arguments, NUL-terminated, to file descriptor 3, followed by a record separator. The environment holds only PATH and HOME, both pointing at directories that do not exist. Pathname expansion is off (set -f), and each run uses a fresh empty working directory. The case is the last thing in the command string, so a trailing backslash behaves as at the end of input. A non-zero exit with no record is a syntax error, and its message is kept. We run dash 0.5.12 and GNU bash 5.2.37 with --posix. For quoting, each quoted form q is run as f q with globbing on, in a directory that holds files named a and decoy.txt, so an unquoted *, ? or [a] changes the result. A quoted form passes only if both shells give exactly one argument equal to the original string.

Cases. gen_cases.py writes 87 split cases in ten groups (Appendix A). Basic splitting (B01–B06) covers spaces, tabs, leading and trailing blanks and the empty string. Single quotes (S01–S09) cover adjacency, empty quotes, backslashes inside single quotes, the '\'' idiom and an unterminated quote. Double quotes (D01–D14) cover each character a backslash may escape inside double quotes ($, `, ", \ and newline) and characters it may not (b, n, x), an unterminated quote and a literal newline. Backslashes outside quotes (E01–E12) cover escaped spaces, quotes, #, $, letters, a backslash at the end of input and backslash-newline. Mixed quoting (Q01–Q08) concatenates quoted and unquoted parts. Unicode and control characters (U01–U07) cover accented letters, no-break space, ideographic space, carriage return, vertical tab, form feed and CJK text. Practical lines (L01–L08) are typical git, python -c, curl, ssh, docker, grep, node -e and find invocations.

Three groups are reported but not scored, because a word splitter is not expected to implement the rest of the shell: comments (C01–C05), operators and newlines (O01–O08) and expansions (X01–X10). They show what each library does when a string contains more than words. One case is open. E06 ends in a backslash. POSIX says an unquoted backslash preserves the literal value of the following character, but at the end of input there is none, so the specification does not fix the result. dash and bash keep the backslash.

Reading of POSIX. The specification fixes the scored behaviour. Inside double quotes, a backslash keeps its special meaning only before $, `, ", \ or a newline; before any other character it is literal (Shell Command Language §2.2.3) [1]. Outside quotes, a backslash quotes the next character, and backslash-newline is removed as a line continuation (§2.2.1). Words are separated by unquoted <blank> characters, which in the POSIX locale are only space and tab (§2.3, Base Definitions §7.3.1); carriage return, vertical tab, form feed and Unicode spaces are ordinary characters. A quote without its closing partner is a syntax error. dash and bash agree with this reading on every scored case.

Classes (analyze.py). A gives the same argument vector as dash. W gives a different vector. R is a library error where dash parses the string. L is an argument vector where dash reports a syntax error, which means the library accepted malformed input. For quoting, OK means both shells read the form back as the original string, FAIL means neither does, FAIL-bash means only bash misreads it, and E means the quoter refused the input.

Harness. run_all.sh builds the Go binary and the Rust binary (cargo build --locked), runs the four language runners on both case files, runs the shell reference, and writes results/. It also runs the real-world sample (§5). The JavaScript dependencies are installed with npm ci from a committed lockfile, and the Go and Rust dependencies are pinned by go.sum and Cargo.lock.

Reproduce.

git clone https://github.com/buildngrowsv/pubroot-pilots
cd pubroot-pilots && git checkout 7eba5c0fa7c5006e927306c3f26bf3479fab3b6e
cd shell-words
cd js && npm ci && cd ..
PY=python3 ./run_all.sh

Requires Node 24, Python 3.13, Go 1.27, Rust 1.85, dash and bash. Outputs are results/split.json, results/quote.json, results/sh_split.json, results/sh_quote.json, results/summary.json, results/report.txt (the full matrix), results/realworld.json and results/versions.txt. Tree: https://github.com/buildngrowsv/pubroot-[REDACTED_SECRET]-words. We ran the script twice on the same machine, with different Python hash seeds, and once more from a git archive export of the commit into a clean directory with a fresh npm ci. All three produced byte-identical files in results/.

4. Results

Outputs differed across the ten libraries on 47 of the 87 strings. Of the 63 scored cases, 29 had at least one deviation from dash. dash and bash --posix gave the same argument vector, or the same syntax error, on all 87. Table 1 gives the counts; Appendix A has the full matrix and Appendix B lists every deviating output.

Table 1. Classes on the 63 scored cases, the 23 shell-only cases and the open case E06.

LibraryScored AWRLShell-only AWRLE06
go-shellquote6300061601R
shlex (Rust)6300081401R
shell-words (Rust)6300081401A
mvdan sh Fields6210014180A
shlex (npm)6030061601R
shlex (Python)5850061601R
google/shlex5760081401R
go-shellwords56700131000R
shell-quote5380261601W
string-argv37240261601A

Three libraries matched dash on every scored case: go-shellquote and the two Rust crates, shlex and shell-words. mvdan/sh deviated once. The pairwise view tells the same story. go-shellquote, Rust shlex and shell-words give the same outcome on all 63 scored cases (counting any error as one outcome), and mvdan/sh differs from them on one. The furthest pair, go-shellwords against string-argv, differs on 28.

Backslash inside double quotes (D05–D08, D10). POSIX keeps a backslash literal inside double quotes unless it precedes $, `, ", \ or newline. go-shellwords and google/shlex drop it before any character, so "a\b" becomes ab and "\x" becomes x. go-shellwords goes further on D08: "a\nb" becomes a, newline, b, so a two-character escape sequence turns into a control character. google/shlex returns anb for the same input. In the other direction, Python’s shlex and npm shlex keep the backslash before $ and ` (D06, D07), so "a\$b" stays a\$b where a shell gives a$b. Python documents this behaviour: in POSIX mode, inside double quotes its escape character escapes only the quote character and itself. shell-quote also keeps the backslash before a backtick (D07). string-argv does not treat backslash as an escape at all, so "a\"b" ends the quoted part at the escaped quote and returns a\b (D03), and "a\\b" keeps both backslashes (D04).

Backslash-newline (D11, E07). A backslash followed by a newline is a line continuation and disappears, both inside double quotes and outside quotes. Five libraries keep it in some form. Python’s shlex keeps the backslash and the newline inside double quotes (D11) and turns a\ newline b into the single word a, newline, b (E07). go-shellwords and google/shlex keep the newline but drop the backslash in both cases. shell-quote keeps both inside double quotes and splits E07 into two words, a and b, as if the newline were a separator. string-argv returns a\ and b. Long commands in configuration files are often wrapped with backslash-newline, so this matters whenever a multi-line string is split.

Escape sequences outside quotes (E09). Outside quotes, \t is just a quoted t, and the shell gives atb for a\tb. go-shellwords returns a, tab, b. Combined with D08, this means go-shellwords interprets C-style escapes that no POSIX shell interprets, and a path such as C:\temp or a regular expression such as \t comes out changed.

Separators (U02–U06). Only space and tab separate words in the POSIX locale, and dash and bash keep carriage return, vertical tab, form feed, no-break space and ideographic space inside a word. shell-quote and string-argv split on all five, because they use JavaScript’s \s, which matches Unicode white space. Seven of the ten split on carriage return (U04): Python shlex, npm shlex, go-shellwords, google/shlex, mvdan/sh, shell-quote and string-argv. Only go-shellquote and the two Rust crates keep it. A carriage return in a command line usually comes from a file with Windows line endings, so these libraries silently drop a trailing \r that the shell would have passed on. This is benign for most commands but means the library and the shell disagree about the last argument.

Unterminated quotes (S08, D12). dash and bash reject 'abc and "abc with a syntax error. Eight libraries also reject them. shell-quote and string-argv return abc, as if the quote had been closed at the end of the string. A caller that relies on the splitter to catch a truncated command line will not get an error from these two.

Trailing backslash (E06, open). For a\, dash and bash return a\. Six libraries report an error (Python shlex, npm shlex, go-shellquote, go-shellwords, google/shlex and Rust shlex), mvdan/sh, shell-words and string-argv return a\, and shell-quote returns a, dropping the backslash. We do not score this case, but rejecting it is the safer choice, and silently dropping a character is the least safe.

string-argv. string-argv deviated on 26 of 63 scored cases, which follows from its design. It handles single and double quotes but has no escape character. Every case with a backslash outside single quotes therefore differs, including the practical case Q08 (--j="x\"y"). Callers who need shell semantics should not use it for strings that may contain backslashes.

Shell-only groups. On comments, Python shlex (with its default comments=False), npm shlex, go-shellquote, go-shellwords and string-argv keep #b as a word in a #b. google/shlex, mvdan/sh and both Rust crates drop it, like the shell. shell-quote returns a comment marker, but it also treats # inside a word as a comment: a#b becomes a plus a comment (C02), where the shell gives the single word a#b. On operators, seven libraries return ;, |, &&, > and & as parts of words or as words. go-shellwords stops at the first operator and returns the words before it, which here equals the first command’s arguments; the rest of the line is dropped unless the caller reads its parser position. shell-quote returns operator markers. mvdan/sh refuses with an error such as “; is not a valid word”. All ten treat a newline as a separator (O07), where the shell starts a new command. On expansions, mvdan/sh expands $HOME from the supplied environment and refuses command substitution. shell-quote expands $HOME and ${X} to empty strings unless the caller passes an environment, and splits $(echo x) into operator markers. The other eight return the text literally. None performs tilde expansion. These are design choices, not errors, but they decide whether a string that contains shell syntax fails loudly or is run as something else.

Quoting. Table 2 gives the round-trip result for each quoter. Four quoters, Python shlex.quote, shell-quote quote, npm shlex quote and Rust shlex try_quote, produced a correct form for all 29 strings in both shells. go-shellquote’s Join left #x unquoted, so both shells read it as a comment and the argument disappears (R18). shell-escape returned an empty string for the empty argument, so the argument vanishes rather than being passed as '' (R01). Rust shell-words left ~ unquoted, so both shells replace it with the home directory (R11). It also left {a,b} unquoted, which dash keeps but bash, even in POSIX mode, expands into two arguments (R22). mvdan/sh’s syntax.Quote with LangPOSIX refused four strings, those containing a newline, a tab, a carriage return or a no-break space, with an error; that is fail-closed, and the caller learns it must choose another quoting. No quoter left a glob character unquoted: *, ? and [a] all survived with decoy files present.

Table 2. Quote round trip over 29 strings (Appendix C).

QuoterOKFAILFAIL-bashE (refused)
shell-quote29000
shell-escape28100
shlex (npm)29000
shlex (Python)29000
go-shellquote28100
mvdan sh Quote25004
shlex (Rust)29000
shell-words (Rust)27110

5. Real-world sample

The synthetic cases show where libraries differ. The sample asks how often real command strings fall into those places. npm runs each entry of a package’s scripts with sh -c on POSIX systems, so dash’s reading is the one that counts, and tools that list, wrap or re-run npm scripts often split them with one of the libraries above.

Sample. We took the first 500 names in the npmTopDownloads list shipped in npm-high-impact 1.13.0 and read the manifest of each package’s latest version from the npm registry on 2026-11-24. The snapshot realworld/npm_scripts.json records name, version and scripts. Published npm versions are immutable, and fetch_npm_scripts.py --verify re-reads the pinned versions. 442 of the 500 packages publish at least one script, and there are 1,402 distinct script strings.

Plain strings. We call a string plain if it contains none of ; | & < > ( ) $ ` newline # ~ * ? [ ] { }. For these, quote removal and word splitting are the whole of what the shell does. 800 of the 1,402 strings are plain, and all ten libraries returned dash’s argument vector for every one of them; dash and bash agreed on all 800. Only 13 of the 800 contain a quote or a backslash, and none contains a backslash, a carriage return or a Unicode space. The defects of §4 sit in characters that npm scripts in this sample almost never use.

Strings that need a shell. The other 602 strings use shell syntax. Most of it is && and & (384 strings contain &), globs (192 contain *), pipes (40), braces (33), subshell parentheses (26), ; (21), redirections (> in 20, < in 2) and $ (18). mvdan/sh’s parser rejected 430 strings as not being a plain list of words. Every other library returned an argument vector for at least 429 of those 430, with operators as words or, for shell-quote, as markers. Only 965 of the 1,402 strings got the same output from all ten libraries.

One manifest in the sample has a script with an unbalanced quote: jsesc 3.1.0’s coveralls script ends in coverage/lcov.info', and a shell rejects it. Python shlex, npm shlex, go-shellquote, google/shlex and both Rust crates reject it as unterminated, and mvdan/sh rejects it for its &&. shell-quote, string-argv and go-shellwords return an argument vector.

Table 3. Real-world sample (npm-high-impact 1.13.0, first 500 of npmTopDownloads, snapshot 2026-11-24).

MeasureValue
Packages / with scripts500 / 442
Distinct script strings1402
Plain strings (no shell syntax beyond quoting)800
Plain strings with a quote or backslash13
dash vs bash –posix differences on plain strings0
Strings where all ten libraries give the same outcome965
Strings rejected by mvdan/sh’s parser430
LibraryPlain: AWRLVectors returned on the strings mvdan/sh rejects
shlex (Python)800000429
shell-quote800000430
string-argv800000430
shlex (npm)800000429
google/shlex800000429
go-shellquote800000429
go-shellwords800000430
mvdan sh Fields8000000
shlex (Rust)800000429
shell-words (Rust)800000429

Characters that made a string non-plain (number of strings containing each): & 384, * 192, | 40, { 33, } 33, ( 26, ) 26, ; 21, > 20, $ 18, [ 4, ] 4, < 2, newline 1, # 1.

6. Implications (hypotheses)

The following are hypotheses drawn from the matrix, not measured effects.

Hypothesis 1: for plain command strings, the choice of splitter rarely matters; for anything else, it matters more than the documentation suggests. All ten libraries agreed with dash on the 800 plain npm scripts. The differences appear with backslashes, line continuations, carriage returns, unterminated quotes and shell syntax, which are exactly the inputs a tool meets when it reads strings written by others.

Hypothesis 2: a splitter that accepts shell syntax without complaint is a correctness risk for tools that then call execve. About 31% of the npm sample (430 of 1,402) uses operators that a shell would act on. Seven of the ten libraries turn a && b into words, and go-shellwords returns only a, so a tool that splits a script and executes it directly will pass && to the first program as an argument. mvdan/sh’s refusal, and shell-quote’s operator markers, give the caller a chance to fall back to sh -c.

Hypothesis 3: round-trip testing through a real shell is a cheap guard for quoting functions. Each of the three quoting defects we found is visible in one line of the round-trip table, and the shell-quote defect behind CVE-2021-42740 [9] was of the same kind. Running each quoter’s output through sh -c in a test suite costs milliseconds.

For library users. If shell fidelity matters, the measured choices are go-shellquote or mvdan/sh on Go, shlex or shell-words on Rust, and npm shlex or shell-quote with care on Node. Python’s shlex.split is close but mishandles \$, \` and backslash-newline inside double quotes. For quoting, prefer a quoter that either produced correct forms for every case or refuses what it cannot quote.

7. Threats to validity

Reference choice. dash is one shell. We also ran bash in POSIX mode, and the two agreed on every split case, which makes an oracle defect unlikely for these inputs. Other shells (zsh, ksh, busybox ash) may differ on some cases, notably word splitting in zsh, which does not split unquoted parameters by default. Our cases contain no unquoted parameters in the scored groups, so this does not affect the scores.

Locale. We ran the shells with an empty environment, which means the POSIX locale, where <blank> is only space and tab. POSIX lets a locale define more blank characters, and we did not test other locales, so the reference for the Unicode spaces in U02 and U03 could differ for a shell running in a UTF-8 locale that classes them as blank. The control characters in U04 to U06 are not blanks in the POSIX locale.

Default options. Several libraries have options that change the results: Python’s shlex.shlex class can be configured with whitespace, escapedquotes and commenters; shell-quote takes an environment and an options object; mvdan/sh takes an environment function. We measured the default entry point that most callers use, with mvdan/sh given the same environment as the shells. A caller using non-default options may see different results.

Case selection. The 87 cases were written to cover the rules in §2.2 and §2.3 of the specification and common command shapes, not sampled from use. The scored deviation counts depend on how many cases probe each rule, so they compare libraries on this case list rather than measure a general error rate. The full list is in Appendix A so readers can judge coverage.

Shell-only groups. Classing a library as W on an operator or expansion case does not mean it is wrong; most libraries do not claim to handle these. We report them separately for that reason.

Sample. The npm sample covers popular packages’ published scripts, which skew towards simple build and test commands. Scripts in application repositories, CI files and agent tool calls may use backslashes and line continuations more often. The sample shows that the measured differences are rare in this population, not that they are rare everywhere.

Version drift. Results are pinned to the listed versions. Some subjects (google/shlex, go-shellquote) have had no release in years; others are actively maintained and may change.

8. Conclusion

Ten libraries that split command lines like a shell agree with each other, and with dash, on simple strings, and all ten matched dash on every one of 800 plain npm scripts. They disagree on 47 of 87 test strings, and 29 of 63 scored cases expose at least one deviation from a real shell. The differences are not random. They follow a short list of rules: the backslash inside double quotes, backslash-newline, which characters separate words, and whether an unterminated quote is an error. go-shellquote and the Rust crates shlex and shell-words matched dash on every scored case. string-argv, which has no escape character, matched on 37. On the quoting side, three of eight functions produced a form that a shell reads differently, and one refused what it could not quote. The matrix, the case list and the harness are pinned at one commit and re-run in seconds, so a library author can check a change against a real shell before releasing it.

Appendix A. Full case list and verdict matrix

Inputs are written as Python string literals (so \n, \t, \r, \x0b, \x0c, \xa0 and \u3000 are single characters). “dash” is dash’s argument vector, or ERR for a syntax error; bash agreed on every case. Columns: Py = Python shlex; sq = shell-quote; sa = string-argv; nx = npm shlex; gs = google/shlex; gq = go-shellquote; gw = go-shellwords; mv = mvdan/sh shell.Fields; rx = Rust shlex; sw = Rust shell-words. Classes: A agree, W different vector, R library error, L accepted where dash errors. Scored: yes, no (shell-only group) or open.

IDInputdashScoredPysqsanxgsgqgwmvrxsw
B01'a b c'['a', 'b', 'c']yesAAAAAAAAAA
B02' a b '['a', 'b']yesAAAAAAAAAA
B03'a\tb'['a', 'b']yesAAAAAAAAAA
B04''[]yesAAAAAAAAAA
B05' '[]yesAAAAAAAAAA
B06'a'['a']yesAAAAAAAAAA
S01"'a b'"['a b']yesAAAAAAAAAA
S02"'a'b'c'"['abc']yesAAAAAAAAAA
S03"''"['']yesAAAAAAAAAA
S04"a''b"['ab']yesAAAAAAAAAA
S05"'a\\b'"['a\\b']yesAAAAAAAAAA
S06"'it'\\''s'"["it's"]yesAAWAAAAAAA
S07'\'a"b\''['a"b']yesAAAAAAAAAA
S08"'abc"ERRyesALLAAAAAAA
S09"x '' y"['x', '', 'y']yesAAAAAAAAAA
D01'"a b"'['a b']yesAAAAAAAAAA
D02'""'['']yesAAAAAAAAAA
D03'"a\\"b"'['a"b']yesAAWAAAAAAA
D04'"a\\\\b"'['a\\b']yesAAWAAAAAAA
D05'"a\\b"'['a\\b']yesAAAAWAWAAA
D06'"a\\$b"'['a$b']yesWAWWAAAAAA
D07'"a\\`b"'['a`b']yesWWWWAAAAAA
D08'"a\\nb"'['a\\nb']yesAAAAWAWAAA
D09'"a\'b"'["a'b"]yesAAAAAAAAAA
D10'"\\x"'['\\x']yesAAAAWAWAAA
D11'"a\\\nb"'['ab']yesWWWAWAWAAA
D12'"abc'ERRyesALLAAAAAAA
D13'x "" y'['x', '', 'y']yesAAAAAAAAAA
D14'"a\nb"'['a\nb']yesAAAAAAAAAA
E01'a\\ b'['a b']yesAAWAAAAAAA
E02'\\a'['a']yesAAWAAAAAAA
E03'\\\\'['\\']yesAAWAAAAAAA
E04"\\'"["'"]yesAAWAAAAAAA
E05'\\"'['"']yesAAWAAAAAAA
E06'a\\'['a\\']openRWARRRRARA
E07'a\\\nb'['ab']yesWWWAWAWAAA
E08'\\#a'['#a']yesAAWAAAAAAA
E09'a\\tb'['atb']yesAAWAAAWAAA
E10'\\ '[' ']yesAAWAAAAAAA
E11'a\\\\ b'['a\\', 'b']yesAAWAAAAAAA
E12'\\$x'['$x']yesAAWAAAAAAA
Q01'a"b c"d'['ab cd']yesAAAAAAAAAA
Q02'"a"\'b\'c'['abc']yesAAAAAAAAAA
Q03'--opt="x y"'['--opt=x y']yesAAAAAAAAAA
Q04'-c \'echo "hi"\''['-c', 'echo "hi"']yesAAAAAAAAAA
Q05'"\'"\'"\''['\'"']yesAAAAAAAAAA
Q06'""\'\''['']yesAAAAAAAAAA
Q07'\'a\'"b"\\ c'['ab c']yesAAWAAAAAAA
Q08'--k=\'v w\' --j="x\\"y"'['--k=v w', '--j=x"y']yesAAWAAAAAAA
U01'héllo wörld'['héllo', 'wörld']yesAAAAAAAAAA
U02'a\xa0b'['a\xa0b']yesAWWAAAAAAA
U03'a\u3000b'['a\u3000b']yesAWWAAAAAAA
U04'a\rb'['a\rb']yesWWWWWAWWAA
U05'a\x0bb'['a\x0bb']yesAWWAAAAAAA
U06'a\x0cb'['a\x0cb']yesAWWAAAAAAA
U07"日本 '語 文'"['日本', '語 文']yesAAAAAAAAAA
L01'git commit -m "fix: it\'s done"'['git', 'commit', '-m', "fix: it's done"]yesAAAAAAAAAA
L02'python -c \'print("a b")\''['python', '-c', 'print("a b")']yesAAAAAAAAAA
L03'curl -H "Accept: */*" https://example.com/a?b=c'['curl', '-H', 'Accept: */*', 'https://example.com/a?b=c']yesAAAAAAAAAA
L04'ssh home \'ls -l \'"\'"\'a b\'"\'"\'\''['ssh', 'home', "ls -l 'a b'"]yesAAAAAAAAAA
L05'docker run -e "A=b c" img'['docker', 'run', '-e', 'A=b c', 'img']yesAAAAAAAAAA
L06"grep -E '^(a|b)+$' file.txt"['grep', '-E', '^(a|b)+$', 'file.txt']yesAAAAAAAAAA
L07'node -e "console.log(\'x y\')"'['node', '-e', "console.log('x y')"]yesAAAAAAAAAA
L08"find . -name '*.py' -print0"['find', '.', '-name', '*.py', '-print0']yesAAAAAAAAAA
C01'a #b'['a']noWWWWAWWAAA
C02'a#b'['a#b']noAWAAAAAAAA
C03'#a'[]noWWWWAWWAAA
C04'a "#b"'['a', '#b']noAAAAAAAAAA
C05"a '#'b"['a', '#b']noAAAAAAAAAA
O01'a;b'['a']noWWWWWWARWW
O02'a|b'['a']noWWWWWWARWW
O03'a&&b'['a']noWWWWWWARWW
O04'a >b'['a']noWWWWWWARWW
O05'a 2>&1'['a']noWWWWWWARWW
O06'(a)'ERRnoLLLLLLAALL
O07'a\nb'['a']noWWWWWWWWWW
O08'a & b'['a']noWWWWWWARWW
X01'$HOME'['/nonexistent-home']noWWWWWWWAWW
X02'"$HOME"'['/nonexistent-home']noWWWWWWWAWW
X03"'$HOME'"['$HOME']noAAAAAAAAAA
X04'${X}y'['y']noWAWWWWWAWW
X05'$(echo x)'['x']noWWWWWWWRWW
X06'`echo x`'['x']noWWWWWWWRWW
X07'~'['/nonexistent-home']noWWWWWWWAWW
X08'~/x'['/nonexistent-home/x']noWWWWWWWAWW
X09'*.txt'['*.txt']noAAAAAAAAAA
X10'a=b c'['a=b', 'c']noAAAAAAAAAA

Appendix B. Deviating outputs

Every non-A cell of Appendix A, with the library’s output. Shell-only groups are included for completeness.

  • S06 sa (W): ['it\\s']
  • S08 sq (L): ['abc']
  • S08 sa (L): ['abc']
  • D03 sa (W): ['a\\b']
  • D04 sa (W): ['a\\\\b']
  • D05 gs (W): ['ab']
  • D05 gw (W): ['ab']
  • D06 Py (W): ['a\\$b']
  • D06 sa (W): ['a\\$b']
  • D06 nx (W): ['a\\$b']
  • D07 Py (W): ['a\\`b']
  • D07 sq (W): ['a\\`b']
  • D07 sa (W): ['a\\`b']
  • D07 nx (W): ['a\\`b']
  • D08 gs (W): ['anb']
  • D08 gw (W): ['a\nb']
  • D10 gs (W): ['x']
  • D10 gw (W): ['x']
  • D11 Py (W): ['a\\\nb']
  • D11 sq (W): ['a\\\nb']
  • D11 sa (W): ['a\\\nb']
  • D11 gs (W): ['a\nb']
  • D11 gw (W): ['a\nb']
  • D12 sq (L): ['abc']
  • D12 sa (L): ['abc']
  • E01 sa (W): ['a\\', 'b']
  • E02 sa (W): ['\\a']
  • E03 sa (W): ['\\\\']
  • E04 sa (W): ['\\']
  • E05 sa (W): ['\\']
  • E06 Py (R): error: ValueError: No escaped character
  • E06 sq (W): ['a']
  • E06 nx (R): error: Got EOF while in an escape sequence
  • E06 gs (R): error: EOF found after escape character
  • E06 gq (R): error: Unterminated backslash-escape
  • E06 gw (R): error: invalid command line string
  • E06 rx (R): error: None (invalid input)
  • E07 Py (W): ['a\nb']
  • E07 sq (W): ['a', 'b']
  • E07 sa (W): ['a\\', 'b']
  • E07 gs (W): ['a\nb']
  • E07 gw (W): ['a\nb']
  • E08 sa (W): ['\\#a']
  • E09 sa (W): ['a\\tb']
  • E09 gw (W): ['a\tb']
  • E10 sa (W): ['\\']
  • E11 sa (W): ['a\\\\', 'b']
  • E12 sa (W): ['\\$x']
  • Q07 sa (W): ['ab\\', 'c']
  • Q08 sa (W): ['--k=v w', '--j=x\\y']
  • U02 sq (W): ['a', 'b']
  • U02 sa (W): ['a', 'b']
  • U03 sq (W): ['a', 'b']
  • U03 sa (W): ['a', 'b']
  • U04 Py (W): ['a', 'b']
  • U04 sq (W): ['a', 'b']
  • U04 sa (W): ['a', 'b']
  • U04 nx (W): ['a', 'b']
  • U04 gs (W): ['a', 'b']
  • U04 gw (W): ['a', 'b']
  • U04 mv (W): ['a', 'b']
  • U05 sq (W): ['a', 'b']
  • U05 sa (W): ['a', 'b']
  • U06 sq (W): ['a', 'b']
  • U06 sa (W): ['a', 'b']
  • C01 Py (W): ['a', '#b']
  • C01 sq (W): ['a', '<comment:b>']
  • C01 sa (W): ['a', '#b']
  • C01 nx (W): ['a', '#b']
  • C01 gq (W): ['a', '#b']
  • C01 gw (W): ['a', '#b']
  • C02 sq (W): ['a', '<comment:b>']
  • C03 Py (W): ['#a']
  • C03 sq (W): ['<comment:a>']
  • C03 sa (W): ['#a']
  • C03 nx (W): ['#a']
  • C03 gq (W): ['#a']
  • C03 gw (W): ['#a']
  • O01 Py (W): ['a;b']
  • O01 sq (W): ['a', '<op:;>', 'b']
  • O01 sa (W): ['a;b']
  • O01 nx (W): ['a;b']
  • O01 gs (W): ['a;b']
  • O01 gq (W): ['a;b']
  • O01 mv (R): error: 1:2: ; is not a valid word
  • O01 rx (W): ['a;b']
  • O01 sw (W): ['a;b']
  • O02 Py (W): ['a\|b']
  • O02 sq (W): ['a', '<op:\|>', 'b']
  • O02 sa (W): ['a\|b']
  • O02 nx (W): ['a\|b']
  • O02 gs (W): ['a\|b']
  • O02 gq (W): ['a\|b']
  • O02 mv (R): error: 1:2: | is not a valid word
  • O02 rx (W): ['a\|b']
  • O02 sw (W): ['a\|b']
  • O03 Py (W): ['a&&b']
  • O03 sq (W): ['a', '<op:&&>', 'b']
  • O03 sa (W): ['a&&b']
  • O03 nx (W): ['a&&b']
  • O03 gs (W): ['a&&b']
  • O03 gq (W): ['a&&b']
  • O03 mv (R): error: 1:2: && is not a valid word
  • O03 rx (W): ['a&&b']
  • O03 sw (W): ['a&&b']
  • O04 Py (W): ['a', '>b']
  • O04 sq (W): ['a', '<op:>>', 'b']
  • O04 sa (W): ['a', '>b']
  • O04 nx (W): ['a', '>b']
  • O04 gs (W): ['a', '>b']
  • O04 gq (W): ['a', '>b']
  • O04 mv (R): error: 1:3: > is not a valid word
  • O04 rx (W): ['a', '>b']
  • O04 sw (W): ['a', '>b']
  • O05 Py (W): ['a', '2>&1']
  • O05 sq (W): ['a', '2', '<op:>&>', '1']
  • O05 sa (W): ['a', '2>&1']
  • O05 nx (W): ['a', '2>&1']
  • O05 gs (W): ['a', '2>&1']
  • O05 gq (W): ['a', '2>&1']
  • O05 mv (R): error: 1:4: >& is not a valid word
  • O05 rx (W): ['a', '2>&1']
  • O05 sw (W): ['a', '2>&1']
  • O06 Py (L): ['(a)']
  • O06 sq (L): ['<op:(>', 'a', '<op:)>']
  • O06 sa (L): ['(a)']
  • O06 nx (L): ['(a)']
  • O06 gs (L): ['(a)']
  • O06 gq (L): ['(a)']
  • O06 rx (L): ['(a)']
  • O06 sw (L): ['(a)']
  • O07 Py (W): ['a', 'b']
  • O07 sq (W): ['a', 'b']
  • O07 sa (W): ['a', 'b']
  • O07 nx (W): ['a', 'b']
  • O07 gs (W): ['a', 'b']
  • O07 gq (W): ['a', 'b']
  • O07 gw (W): ['a', 'b']
  • O07 mv (W): ['a', 'b']
  • O07 rx (W): ['a', 'b']
  • O07 sw (W): ['a', 'b']
  • O08 Py (W): ['a', '&', 'b']
  • O08 sq (W): ['a', '<op:&>', 'b']
  • O08 sa (W): ['a', '&', 'b']
  • O08 nx (W): ['a', '&', 'b']
  • O08 gs (W): ['a', '&', 'b']
  • O08 gq (W): ['a', '&', 'b']
  • O08 mv (R): error: 1:3: & is not a valid word
  • O08 rx (W): ['a', '&', 'b']
  • O08 sw (W): ['a', '&', 'b']
  • X01 Py (W): ['$HOME']
  • X01 sq (W): ['']
  • X01 sa (W): ['$HOME']
  • X01 nx (W): ['$HOME']
  • X01 gs (W): ['$HOME']
  • X01 gq (W): ['$HOME']
  • X01 gw (W): ['$HOME']
  • X01 rx (W): ['$HOME']
  • X01 sw (W): ['$HOME']
  • X02 Py (W): ['$HOME']
  • X02 sq (W): ['']
  • X02 sa (W): ['$HOME']
  • X02 nx (W): ['$HOME']
  • X02 gs (W): ['$HOME']
  • X02 gq (W): ['$HOME']
  • X02 gw (W): ['$HOME']
  • X02 rx (W): ['$HOME']
  • X02 sw (W): ['$HOME']
  • X04 Py (W): ['${X}y']
  • X04 sa (W): ['${X}y']
  • X04 nx (W): ['${X}y']
  • X04 gs (W): ['${X}y']
  • X04 gq (W): ['${X}y']
  • X04 gw (W): ['${X}y']
  • X04 rx (W): ['${X}y']
  • X04 sw (W): ['${X}y']
  • X05 Py (W): ['$(echo', 'x)']
  • X05 sq (W): ['$', '<op:(>', 'echo', 'x', '<op:)>']
  • X05 sa (W): ['$(echo', 'x)']
  • X05 nx (W): ['$(echo', 'x)']
  • X05 gs (W): ['$(echo', 'x)']
  • X05 gq (W): ['$(echo', 'x)']
  • X05 gw (W): ['$(echo x)']
  • X05 mv (R): error: unexpected command substitution at 1:1
  • X05 rx (W): ['$(echo', 'x)']
  • X05 sw (W): ['$(echo', 'x)']
  • X06 Py (W): ['`echo', 'x`']
  • X06 sq (W): ['`echo', 'x`']
  • X06 sa (W): ['`echo', 'x`']
  • X06 nx (W): ['`echo', 'x`']
  • X06 gs (W): ['`echo', 'x`']
  • X06 gq (W): ['`echo', 'x`']
  • X06 gw (W): ['`echo x`']
  • X06 mv (R): error: unexpected command substitution at 1:1
  • X06 rx (W): ['`echo', 'x`']
  • X06 sw (W): ['`echo', 'x`']
  • X07 Py (W): ['~']
  • X07 sq (W): ['~']
  • X07 sa (W): ['~']
  • X07 nx (W): ['~']
  • X07 gs (W): ['~']
  • X07 gq (W): ['~']
  • X07 gw (W): ['~']
  • X07 rx (W): ['~']
  • X07 sw (W): ['~']
  • X08 Py (W): ['~/x']
  • X08 sq (W): ['~/x']
  • X08 sa (W): ['~/x']
  • X08 nx (W): ['~/x']
  • X08 gs (W): ['~/x']
  • X08 gq (W): ['~/x']
  • X08 gw (W): ['~/x']
  • X08 rx (W): ['~/x']
  • X08 sw (W): ['~/x']

Appendix C. Quote round trip

Each string was quoted by each library, and the quoted form run as f <form> in dash and bash with globbing on. Columns: sq = shell-quote; se = shell-escape; nx = npm shlex; Py = Python shlex.quote; gq = go-shellquote Join; mv = mvdan/sh syntax.Quote; rx = Rust shlex try_quote; sw = shell-words quote. Classes as in §3. Non-OK cells show the quoted form.

IDInputsqsenxPygqmvrxsw
R01''OKFAIL ''OKOKOKOKOKOK
R02'a b'OKOKOKOKOKOKOKOK
R03"it's"OKOKOKOKOKOKOKOK
R04'a"b'OKOKOKOKOKOKOKOK
R05'$HOME'OKOKOKOKOKOKOKOK
R06'`x`'OKOKOKOKOKOKOKOK
R07'\\'OKOKOKOKOKOKOKOK
R08'a\nb'OKOKOKOKOKEOKOK
R09'!'OKOKOKOKOKOKOKOK
R10'*'OKOKOKOKOKOKOKOK
R11'~'OKOKOKOKOKOKOKFAIL '~'
R12'-n'OKOKOKOKOKOKOKOK
R13'héllo'OKOKOKOKOKOKOKOK
R14'\t'OKOKOKOKOKEOKOK
R15"'"OKOKOKOKOKOKOKOK
R16'"'OKOKOKOKOKOKOKOK
R17' lead'OKOKOKOKOKOKOKOK
R18'#x'OKOKOKOKFAIL '#x'OKOKOK
R19';'OKOKOKOKOKOKOKOK
R20"a\\'b"OKOKOKOKOKOKOKOK
R21'$(x)'OKOKOKOKOKOKOKOK
R22'{a,b}'OKOKOKOKOKOKOKFAIL-bash '{a,b}'
R23'a\rb'OKOKOKOKOKEOKOK
R24'\xa0'OKOKOKOKOKEOKOK
R25'=x'OKOKOKOKOKOKOKOK
R26'[a]'OKOKOKOKOKOKOKOK
R27'a*'OKOKOKOKOKOKOKOK
R28'?'OKOKOKOKOKOKOKOK
R29'é b'OKOKOKOKOKOKOKOK

References

  1. The Open Group. The Open Group Base Specifications Issue 8, IEEE Std 1003.1-2024. Shell Command Language, §2.2 Quoting, §2.3 Token Recognition; Base Definitions §7.3.1. https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html
  2. W. M. McKeeman. Differential Testing for Software. Digital Technical Journal 10(1), 1998.
  3. M. Greenberg, A. J. Blatt. Executable Formal Semantics for the POSIX Shell. Proc. ACM Program. Lang. 4 (POPL), 2020. https://doi.org/10.1145/3371111
  4. Y. Régis-Gianas, N. Jeannerod, R. Treinen. Morbig: A Static Parser for POSIX Shell. SLE 2018. https://doi.org/10.1145/3276604.3276615
  5. M. Greenberg. Word Expansion Supports POSIX Shell Interactivity. Programming ‘18 Companion, 2018. https://doi.org/10.1145/3191697.3214336
  6. N. Vasilakis, K. Kallas, K. Mamouras, A. Benetopoulos, L. Cvetković. PaSh: Light-touch Data-Parallel Shell Processing. EuroSys 2021. https://doi.org/10.1145/3447786.3456228
  7. CPython, Lib/test/test_shlex.py, and the shlex module documentation. https://github.com/python/cpython/blob/main/Lib/test/test_shlex.py ; https://docs.python.org/3/library/shlex.html
  8. mattn/go-shellwords, shellwords_test.go. https://github.com/mattn/go-shellwords/blob/master/shellwords_test.go
  9. GitHub Advisory GHSA-g4rg-993r-mgx7 / CVE-2021-42740: Improper Neutralization of Special Elements used in a Command in shell-quote. https://github.com/advisories/GHSA-g4rg-993r-mgx7
  10. Subject libraries: ljharb/shell-quote, mccormicka/string-argv, rgov/node-shlex, xxorax/node-shell-escape, google/shlex, kballard/go-shellquote, mattn/go-shellwords, mvdan/sh, comex/rust-shlex, tmiasko/shell-words. https://github.com/ljharb/shell-quote ; https://github.com/mccormicka/string-argv ; https://github.com/rgov/node-shlex ; https://github.com/xxorax/node-shell-escape ; https://github.com/google/shlex ; https://github.com/kballard/go-shellquote ; https://github.com/mattn/go-shellwords ; https://github.com/mvdan/sh ; https://github.com/comex/rust-shlex ; https://github.com/tmiasko/shell-words
  11. wooorm/npm-high-impact 1.13.0. https://github.com/wooorm/npm-high-impact
  12. A. King. Revalidation Under Test: How Fourteen Static-File Servers Evaluate HTTP Preconditions. Pubroot 2026-567, 2026. (Self-citation.)