---
# System prepended metadata

title: Query 186

---

You can create a shell script that checks whether GitHub Copilot is already installed in Visual Studio Code and proceeds with the installation if it's not. Here's a simple script to achieve this [1][2]:
```shellscript
#!/bin/bash

# Check if Visual Studio Code is installed
if ! command -v code &>/dev/null; then
  echo "Visual Studio Code is not installed. Please install it first."
  exit 1
fi

# Check if GitHub Copilot extension is already installed
if code --list-extensions | grep -q 'github.copilot'; then
  echo "GitHub Copilot is already installed in Visual Studio Code."
else
  # Install GitHub Copilot extension
  code --install-extension github.copilot
  echo "GitHub Copilot has been installed in Visual Studio Code."
fi
```
Here's how the script works:
* It checks if Visual Studio Code is installed by attempting to run the code command.
* If Visual Studio Code is not installed, it displays an error message and exits.
* It then checks if the GitHub Copilot extension is already installed by listing the installed extensions and looking for the github.copilot extension identifier.
* If GitHub Copilot is already installed, it displays a message confirming this.
* If GitHub Copilot is not installed, it uses the code --install-extension command to install the extension and confirms the installation.

To use this script:
1. Save it to a file, e.g., `install-github-copilot.sh`.
2. Make the script executable:
    ```
    chmod +x install-github-copilot.sh
    ```
3. Run the script:
    ```
    ./install-github-copilot.sh
    ```
    
The script will either confirm that GitHub Copilot is already installed or proceed with the installation process if it's not found in Visual Studio Code.