{"record":{"id":"44249a2f93c55493","repo":"dagger/dagger","slug":"environment-variable-q-not-set","errorCode":null,"errorMessage":"environment variable %q not set","messagePattern":"environment variable %q not set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/dagger/shell_commands.go","lineNumber":729,"sourceCode":"\t\t\tState: NoState,\n\t\t\tRun: func(ctx context.Context, cmd *ShellCommand, args []string, _ *ShellState) error {\n\t\t\t\thc := interp.HandlerCtx(ctx)\n\n\t\t\t\tif len(args) == 0 {\n\t\t\t\t\t// Print all environment variables\n\t\t\t\t\tfor name, vr := range hc.Env.Each {\n\t\t\t\t\t\tfmt.Fprintf(hc.Stdout, \"%s=%s\\n\", name, vr)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\n\t\t\t\t// Print a specific environment variable\n\t\t\t\tname := args[0]\n\n\t\t\t\tv := hc.Env.Get(name)\n\t\t\t\tif !v.IsSet() {\n\t\t\t\t\treturn fmt.Errorf(\"environment variable %q not set\", name)\n\t\t\t\t}\n\n\t\t\t\treturn h.Print(ctx, v.String())\n\t\t\t},\n\t\t},\n\t\t&ShellCommand{\n\t\t\tUse: \".wait [id...]\",\n\t\t\tDescription: `Wait for background processes to complete\n\n'id' is the process or job ID. If no ID is specified, .wait always returns 0 (zero).\nOtherwise, it returns the exit status of the first command that failed. When multiple\nprocesses are given, the command waits for all processes to complete.\n\nExample:\n\n  container | from alpine | with-exec false | stdout &\n  job1=$!\n  .echo \"job id: $job1\"","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/internal/cmd/dagger/shell_commands.go#L711-L747","documentation":"The shell's `.printenv <name>` builtin reads the variable from the interpreter's environment (`hc.Env.Get(name)`); if `v.IsSet()` is false it throws this error. It mirrors POSIX `printenv` semantics: only set variables can be printed.","triggerScenarios":"`.printenv NAME` where NAME is not present in the shell session's environment — never exported, misspelled, or defined only inside containers rather than the host shell session.","commonSituations":"Referencing an env var that exists in .env files not loaded into the shell session; expecting container-level env (`with-env-variable`) to be visible to the host shell; case-sensitivity mistakes (PATH vs Path).","solutions":["Export the variable in the shell session before calling `.printenv` (export NAME=...)","Run `.printenv` with no args to list all set variables and confirm the exact name","Check casing/spelling of the variable name"],"exampleFix":"# before\n> .printenv API_TOKEN\nenvironment variable \"API_TOKEN\" not set\n# after\n> export API_TOKEN=xxx\n> .printenv API_TOKEN","handlingStrategy":"validation","validationCode":"# check before printing\n.printenv             # list all set vars\n.test -n \"$API_TOKEN\" && .printenv API_TOKEN","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export needed vars in the shell session before use","Remember container env vars are not host shell env vars","Watch case sensitivity of variable names"],"tags":["environment-variables","dagger-shell","cli"],"backgroundTag":"missing-env-var","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}