{"record":{"id":"280d25ebadb00084","repo":"hashicorp/packer","slug":"bad-script-s-s-280d25","errorCode":null,"errorMessage":"Bad script '%s': %s","messagePattern":"Bad script '(.+?)': (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":170,"sourceCode":"\t\t\terrors.New(\"Only one of script or scripts can be specified.\"))\n\t}\n\n\tif p.config.Script != \"\" {\n\t\tp.config.Scripts = []string{p.config.Script}\n\t}\n\n\tif len(p.config.Scripts) == 0 && p.config.Inline == nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Either a script file or inline script must be specified.\"))\n\t} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {\n\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\terrors.New(\"Only a script file or an inline script can be specified, not both.\"))\n\t}\n\n\tfor _, path := range p.config.Scripts {\n\t\tif _, err := os.Stat(path); err != nil {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Bad script '%s': %s\", path, err))\n\t\t}\n\t}\n\n\t// Do a check for bad environment variables, such as '=foo', 'foobar'\n\tfor _, kv := range p.config.Vars {\n\t\tvs := strings.SplitN(kv, \"=\", 2)\n\t\tif len(vs) != 2 || vs[0] == \"\" {\n\t\t\terrs = packersdk.MultiErrorAppend(errs,\n\t\t\t\tfmt.Errorf(\"Environment variable not in format 'key=value': %s\", kv))\n\t\t}\n\t}\n\n\tif errs != nil && len(errs.Errors) > 0 {\n\t\treturn errs\n\t}\n\n\treturn nil\n}","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L152-L188","documentation":"During Prepare, the shell provisioner stats every file listed in the scripts configuration. If os.Stat fails for any path (missing file, bad permissions, wrong type), the path and cause are appended to the validation error list. Packer refuses to start the build so the failure happens before any guest interaction.","triggerScenarios":"scripts contains a path that does not exist relative to the Packer working directory, is a directory, or is unreadable by the user running Packer.","commonSituations":"Relative script paths resolved from a different working directory in CI; typos in filenames; scripts deleted by a previous build step; invoking Packer from a different directory than expected; case-sensitivity mismatches on Linux.","solutions":["Verify each scripts entry exists: run ls on the exact path from the same directory Packer runs in.","Use paths relative to the template file or absolute paths to avoid working-directory ambiguity.","Check file permissions so the Packer process can read the script.","Fix typos or remove stale entries from the scripts list."],"exampleFix":"// before\n\"scripts\": [\"./scripst/setup.sh\"]\n// after (correct the path)\n\"scripts\": [\"./scripts/setup.sh\"]","handlingStrategy":"validation","validationCode":"# shell: verify every scripts entry exists and is readable\nfor f in $SCRIPTS; do test -r \"$f\" || echo \"missing/unreadable: $f\"; done","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run packer validate before building; it surfaces missing script files.","Use absolute paths or paths relative to the template file.","Check case-sensitive filenames on Linux guests/hosts.","Ensure the Packer process user can read each script."],"tags":["validation","configuration","shell","file-not-found"],"backgroundTag":"script-file-not-found","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}