Switching from PowerShell to Bash: Setting Up WSL and Running Azure CLI in Visual Studio Code

Published: (March 10, 2026 at 09:50 PM EDT)
6 min read
Source: Dev.to

Source: Dev.to

Why Switch to Bash?

  • Many Azure, DevOps, and cloud tutorials are written for Bash.
  • PowerShell and Bash have different syntax rules (e.g., $ for variables in PowerShell).
  • Understanding both shells helps you avoid “syntax‑related” errors and makes it easier to follow Linux‑centric documentation.

1. Install Windows Subsystem for Linux (WSL)

1.1 Quick Install via PowerShell (Admin)

# Open PowerShell as Administrator and run:
wsl --install

What happens?

  • The command enables the required Windows features (Windows Subsystem for Linux and Virtual Machine Platform).
  • It then prompts you to restart the machine.
  • After the reboot, running wsl --install again will download and install the default Linux distribution (Ubuntu).

1.2 Manual Feature Enable (Alternative)

  1. Press Win + R, type optionalfeatures.exe, and press Enter.
  2. In the Turn Windows features on or off dialog, check:
    • Windows Subsystem for Linux
    • Virtual Machine Platform
  3. Click OKRestart now.

After the restart, open an elevated PowerShell and run:

wsl --install

1.3 First‑Run Setup

  • The Ubuntu distribution downloads and installs automatically.
  • You’ll be asked to create a UNIX username and password.
    • The password characters are hidden for security—just type and press Enter.

You now have a functional Linux environment accessible via wsl.

2. Open a Bash Terminal in Visual Studio Code

  1. Launch VS Code.
  2. From the top menu, select Terminal → New Terminal.
  3. Click the dropdown arrow next to the plus (+) icon in the terminal panel.
  4. Choose the Bash profile (it should be listed automatically if WSL is installed).

The terminal will switch from PowerShell to Bash and display something like:

username@DESKTOP:~$

2.1 Navigate to a Windows Folder from Bash

cd /mnt/c/Path/To/Your/Folder
# Example:
cd "/mnt/c/Users/YourName/Documents/Linux Servers"

Note: Windows drives are mounted under /mnt/<drive-letter>/.

2.2 Shorten the Bash Prompt (Optional)

Bash shows the full path by default. To display only the hostname and current folder:

# Add this line to ~/.bashrc for a permanent change
echo "PS1='\\h:\\W$ '" >> ~/.bashrc
source ~/.bashrc

Resulting prompt:

DESKTOP:Servers$

3. Using Azure CLI in Bash

With Bash open, you can run any Azure CLI command just as you would in PowerShell:

# Log in to Azure
az login

# List your subscriptions
az account list --output table

# Create a resource group (example)
az group create --name MyResourceGroup --location eastus

Because Azure CLI is cross‑platform, the same commands work in both PowerShell and Bash.

4. Recap of Key Differences

FeaturePowerShellBash (WSL)
Variable prefix$var$var (same) but syntax for arrays, hashes differs
Command chaining; or &&; or &&
Path separator\ (Windows)/ (Linux)
Prompt customization$PROFILE / $Host.UI.RawUIPS1 variable
Default terminal in VS CodePowerShellBash (if WSL installed)

Understanding these differences helps you decide which shell to use for a given tutorial or workflow.

5. Quick Reference Commands

TaskPowerShellBash
Install WSLwsl --install (admin)Same
List installed distroswsl -l -vSame
Open Bash in VS Codecode . → Terminal → BashSame
Change promptN/A (use $PROFILE)PS1='\\h:\\W$ '
Restart Windowsshutdown /r /t 0sudo reboot (inside WSL)

🎉 You’re all set!

You now have:

  • WSL installed and configured.
  • Bash as a terminal option inside Visual Studio Code.
  • The ability to run Azure CLI commands in a Linux‑style environment.

Feel free to explore further—install additional Linux distributions (wsl --list --online), customize your Bash profile, or integrate other DevOps tools (Docker, Terraform, etc.) within this setup. Happy coding!

PowerShell vs Bash Variable Syntax

One of the first differences I noticed between PowerShell and Bash is how variables are defined.

  • PowerShell – variables must begin with the $ symbol.
  • Bash – variables are defined without the $ symbol; the $ is only used when referencing the variable.

Create an Azure Resource Group from Bash

A Resource Group in Azure is a container that holds related resources for an application (e.g., virtual machines, storage accounts, databases).

Steps

  1. Define your variables

    RG="Testing-10-rg"
    LOCATION="eastus"

    Or define them together using the line‑continuation character (\):

    RG="Testing-10-rg" \
    LOCATION="eastus"
  2. Create the resource group

    az group create --name "$RG" --location "$LOCATION"
    • When referencing a variable in a command, prefix it with $ so Bash substitutes the value.
    • Check the provisioningState in the output to verify that the resource group was created successfully.
  3. Verify the creation

    az group list --output table
  4. Delete the resource group (optional)

    az group delete --name "$RG"

    Azure will prompt:

    Are you sure you want to perform this operation? (y/n)

    Type y or yes to confirm.

Conclusion

Switching between shell environments can feel confusing at first, especially when small syntax differences cause commands to behave unexpectedly. Moving from PowerShell to Bash helped me understand how different shells handle:

  • Variable definition and expansion
  • Command syntax
  • Filesystem navigation

By installing Windows Subsystem for Linux (WSL) and using it inside Visual Studio Code, I could run a Linux‑based Bash environment directly on Windows while managing Azure resources through the Azure CLI.

The transition introduced challenges—such as differing variable syntax and path conventions—but it also made me more comfortable working across multiple terminal environments. These skills are especially useful when working with:

  • Cloud infrastructure
  • Linux servers
  • Automation tools (e.g., scripts, CI/CD pipelines)

Understanding both PowerShell and Bash gives developers and cloud engineers greater flexibility across platforms.

Discussion

If you’re also learning Azure or DevOps tools, feel free to share what confused you the most when switching between PowerShell and Bash!

0 views
Back to Blog

Related posts

Read more »