{"record":{"id":"34de86dc8de9745e","repo":"golang/go","slug":"unterminated-quoted-argument","errorCode":null,"errorMessage":"unterminated quoted argument","messagePattern":"unterminated quoted argument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/engine.go","lineNumber":418,"sourceCode":"\t}\n\n\tfor i := 0; ; i++ {\n\t\tif !quoted && (i >= len(line) || strings.ContainsRune(argSepChars, rune(line[i]))) {\n\t\t\t// Found arg-separating space.\n\t\t\tif start >= 0 {\n\t\t\t\trawArg = append(rawArg, argFragment{s: line[start:i], quoted: false})\n\t\t\t\tstart = -1\n\t\t\t}\n\t\t\tif err := flushArg(); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif i >= len(line) || line[i] == '#' {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tif i >= len(line) {\n\t\t\treturn nil, errors.New(\"unterminated quoted argument\")\n\t\t}\n\t\tif line[i] == '\\'' {\n\t\t\tif !quoted {\n\t\t\t\t// starting a quoted chunk\n\t\t\t\tif start >= 0 {\n\t\t\t\t\trawArg = append(rawArg, argFragment{s: line[start:i], quoted: false})\n\t\t\t\t}\n\t\t\t\tstart = i + 1\n\t\t\t\tquoted = true\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// 'foo''bar' means foo'bar, like in rc shell and Pascal.\n\t\t\tif i+1 < len(line) && line[i+1] == '\\'' {\n\t\t\t\trawArg = append(rawArg, argFragment{s: line[start:i], quoted: true})\n\t\t\t\tstart = i + 1\n\t\t\t\ti++ // skip over second ' before next iteration\n\t\t\t\tcontinue\n\t\t\t}","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/engine.go#L400-L436","documentation":"Thrown by the script parser when a single-quote opens a quoted chunk that is never closed before the end of the line. The parser scans char by char; on reaching i >= len(line) while still inside a quoted region (quoted == true) it returns this error. Single quotes are the only quoting mechanism in the script grammar and '' inside doubles to embed a literal quote.","triggerScenarios":"A script line with an odd number of single quotes, e.g. `cat 'foo`, or `echo 'Don't communicate'` (the apostrophe in Don't closes the quote early and the rest is misparsed), or a trailing unclosed argument like `cd 'some path`.","commonSituations":"Embedding an apostrophe in a quoted string without doubling it (the script grammar, like rc/Pascal, uses '' for a literal quote). Copy-pasting a path with a quote. A multi-line value accidentally collapsed onto one line leaving an open quote.","solutions":["Close every opening single quote with a matching closing quote.","To embed a literal single quote, double it: `'Don''t'` yields `Don't`.","If a value contains many quotes, consider an environment variable set via Setenv instead of inline quoting."],"exampleFix":"// before\necho 'Don't communicate by sharing memory'\n# -> unterminated quoted argument\n\n// after (double the inner quote)\necho 'Don''t communicate by sharing memory'","handlingStrategy":"validation","validationCode":"// Ensure every opening single quote is matched.\nfunc balancedQuotes(line string) error {\n    inQuote := false\n    for i := 0; i < len(line); i++ {\n        if line[i] == '\\'' {\n            if !inQuote { inQuote = true; continue }\n            if i+1 < len(line) && line[i+1] == '\\'' { i++; continue } // doubled\n            inQuote = false\n        }\n    }\n    if inQuote { return errors.New(\"unterminated quoted argument\") }\n    return nil\n}","typeGuard":"func isUnterminatedQuote(err error) bool {\n    return err != nil && err.Error() == \"unterminated quoted argument\"\n}","tryCatchPattern":"// Lint script files for unbalanced single quotes before running them.","preventionTips":["Close every opening single quote.","Double inner quotes ('') to embed a literal quote.","Move quote-heavy values into env vars set via Setenv."],"tags":["script","parser","quoting","test-framework","syntax-error"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}