Switching from PowerShell to Bash: Setting Up WSL and Running Azure CLI in Visual Studio Code
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 LinuxandVirtual Machine Platform). - It then prompts you to restart the machine.
- After the reboot, running
wsl --installagain will download and install the default Linux distribution (Ubuntu).
1.2 Manual Feature Enable (Alternative)
- Press Win + R, type
optionalfeatures.exe, and press Enter. - In the Turn Windows features on or off dialog, check:
- Windows Subsystem for Linux
- Virtual Machine Platform
- Click OK → Restart 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
- Launch VS Code.
- From the top menu, select Terminal → New Terminal.
- Click the dropdown arrow next to the plus (+) icon in the terminal panel.
- 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
| Feature | PowerShell | Bash (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.RawUI | PS1 variable |
| Default terminal in VS Code | PowerShell | Bash (if WSL installed) |
Understanding these differences helps you decide which shell to use for a given tutorial or workflow.
5. Quick Reference Commands
| Task | PowerShell | Bash |
|---|---|---|
| Install WSL | wsl --install (admin) | Same |
| List installed distros | wsl -l -v | Same |
| Open Bash in VS Code | code . → Terminal → Bash | Same |
| Change prompt | N/A (use $PROFILE) | PS1='\\h:\\W$ ' |
| Restart Windows | shutdown /r /t 0 | sudo 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
-
Define your variables
RG="Testing-10-rg" LOCATION="eastus"Or define them together using the line‑continuation character (
\):RG="Testing-10-rg" \ LOCATION="eastus" -
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
provisioningStatein the output to verify that the resource group was created successfully.
- When referencing a variable in a command, prefix it with
-
Verify the creation
az group list --output table -
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
yoryesto 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!