{"record":{"id":"a064367d0d092518","repo":"angular/angular-cli","slug":"shell-environment-variable-not-set-angular-cli","errorCode":null,"errorMessage":"`$SHELL` environment variable not set. Angular CLI autocompletion only supports Bash or Zsh. If you're on Windows, Cmd and Powershell don't support command autocompletion, but Git Bash or Windows Subsystem for Linux should work, so please try again in one of those environments.","messagePattern":"`\\$SHELL` environment variable not set\\. Angular CLI autocompletion only supports Bash or Zsh\\. If you're on Windows, Cmd and Powershell don't support command autocompletion, but Git Bash or Windows Subsystem for Linux should work, so please try again in one of those environments\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular/cli/src/utilities/completion.ts","lineNumber":207,"sourceCode":"      .join(' ')\n      .trim(),\n    true,\n  );\n\n  return autocomplete;\n}\n\n/**\n * Sets up autocompletion for the user's terminal. This attempts to find the configuration file for\n * the current shell (`.bashrc`, `.zshrc`, etc.) and append a command which enables autocompletion\n * for the Angular CLI. Supports only Bash and Zsh. Returns whether or not it was successful.\n * @return The full path of the configuration file modified.\n */\nexport async function initializeAutocomplete(): Promise<string> {\n  // Get the currently active `$SHELL` and `$HOME` environment variables.\n  const shell = env['SHELL'];\n  if (!shell) {\n    throw new Error(\n      '`$SHELL` environment variable not set. Angular CLI autocompletion only supports Bash or' +\n        \" Zsh. If you're on Windows, Cmd and Powershell don't support command autocompletion,\" +\n        ' but Git Bash or Windows Subsystem for Linux should work, so please try again in one of' +\n        ' those environments.',\n    );\n  }\n  const home = env['HOME'];\n  if (!home) {\n    throw new Error(\n      '`$HOME` environment variable not set. Setting up autocompletion modifies configuration files' +\n        ' in the home directory and must be set.',\n    );\n  }\n\n  // Get all the files we can add `ng completion` to which apply to the user's `$SHELL`.\n  const runCommandCandidates = getShellRunCommandCandidates(shell, home);\n  if (!runCommandCandidates) {\n    throw new Error(","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular/cli/src/utilities/completion.ts#L189-L225","documentation":"Angular CLI's `initializeAutocomplete` sets up shell autocompletion by first reading the `$SHELL` environment variable to determine which shell the user runs. If `$SHELL` is unset, the CLI cannot detect a supported shell (Bash or Zsh) and throws this error instead of guessing. The message also clarifies that Windows Cmd/PowerShell are unsupported and suggests Git Bash or WSL.","triggerScenarios":"Calling `ng completion` (or code paths `run`/`considerSettingUpAutocompletion` that invoke `initializeAutocomplete`) in an environment where the `SHELL` environment variable is not defined in `process.env`.","commonSituations":"Windows Cmd or PowerShell sessions (which never set `$SHELL`), spawning the CLI from a GUI app or IDE terminal that strips environment variables, running via `env -i` or a sanitized CI container, or cron/systemd jobs with a minimal env.","solutions":["Run the command from Bash or Zsh where `$SHELL` is set (e.g. `bash -lc 'ng completion'`).","On Windows, use Git Bash or Windows Subsystem for Linux instead of Cmd/PowerShell.","Export the variable explicitly if your environment strips it: `export SHELL=$(which bash)` before invoking the CLI.","Skip autocompletion setup with `NG_CLI_COMPLETION=false` if you do not need it."],"exampleFix":"// before (fails in sanitized env)\nng completion\n// after\nexport SHELL=$(which bash)\nng completion","handlingStrategy":"validation","validationCode":"if (!process.env.SHELL) {\n  console.warn('Skipping ng completion: $SHELL is not set.');\n} else {\n  // safe to invoke ng completion\n}","typeGuard":"function hasShellEnv(env: NodeJS.ProcessEnv): env is NodeJS.ProcessEnv & { SHELL: string } {\n  return typeof env.SHELL === 'string' && env.SHELL.length > 0;\n}","tryCatchPattern":"try {\n  await ngCompletionSetup();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('$SHELL` environment variable not set')) {\n    // fall back: skip autocompletion setup\n  } else { throw e; }\n}","preventionTips":["Always invoke ng completion from an interactive Bash/Zsh session.","On Windows use Git Bash or WSL, never Cmd/PowerShell.","Set SHELL explicitly in CI containers (e.g. ENV SHELL=/bin/bash).","Set NG_CLI_COMPLETION=false in environments where completion setup is unwanted."],"tags":["environment","shell","autocompletion","angular-cli"],"backgroundTag":"missing-env-var","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}