- The Subsystem Windows all with Linux (WSL) allows you to run a real Linux environment and Bash scripts directly on Windows.
- The integration between Windows and WSL allows for hybrid work, combining tools, files, and automation from both systems.
- Creating and running Bash scripts in WSL is optimal for both developers and administrators, facilitating everything from simple tasks to advanced workflows.
The rise of mixed-environment development and system administration has boosted the use of Bash within Windows, especially thanks to the arrival of the Windows Subsystem for Linux (WSL). This has removed previous barriers for those who needed to use native Linux scripts and utilities without leaving the comfort of Windows. Now, automate tasks, manage servers or simply learn commands Linux is possible without complicated virtualization or dual booting.
This article is a comprehensive, practical guide for those who want to create, run, and leverage Bash scripts on Windows using WSL. Here you'll find everything from explanations and configuration of the environment, distribution installation, editor usage, file management, interoperability critical points, and advanced debugging and automation tips. If you want to master Bash integration on Windows, this resource is for you.
What is Bash and why use it on Windows with WSL?
Bash It is the most popular shell or command interpreter on Linux systems and Unix, widely used to automate processes, manage servers, perform maintenance tasks, and facilitate development. For its part, the Windows Subsystem for Linux (WSL) is a Microsoft technology that allows you to run a complete Linux environment on top of Windows, merging the best of both systems without the need for Virtual machines heavy or complex configurations.
Thanks to this integration, You can run Bash scripts, access native Linux tools, manage files, and combine Windows and Linux commands. in a single workflow. This is especially useful for developers, administrators, and enthusiasts who work in heterogeneous environments or want to take advantage of the best of both worlds.
Getting Started: WSL Requirements and Pre-Configuration
Before diving into the world of Bash on Windows, make sure your system meets some basic requirements:
- Windows 10 version 1607 or higher, or Windows 11.
- 64-bit operating system.
- Virtualization enabled in BIOS/UEFI.
With this, you can now prepare the environment:
- Activate WSL: Opens PowerShell as administrator and run:
wsl --installor use the classic Control Panel to activate "Windows Subsystem for Linux". - Enables the virtual machine platform (only needed for WSL 2):
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart - Update the Linux kernel (if necessary): Download the Microsoft package to get the latest kernel.
- Set WSL 2 as default:
wsl --set-default-version 2 - Restart the PC to apply the changes.
Once this is done, you can install your favorite Linux distribution (such as Ubuntu, Debian, Fedora…) directly from the Microsoft Store.

Installing and configuring a Linux distribution
The next step is to install your preferred distribution from the Microsoft Store, with Ubuntu being the most popular and recommended option. for starters.
- Search for “Ubuntu” in the Microsoft Store and select the version you’re interested in.
- Click “Get” and “Install.”
- Once installed, open it from the start menu. The first time you run it, it will ask you to create a unique username and password for Linux (these are not connected to your Windows account).
Remember to save this data carefully! They will be necessary to manage administrative tasks with sudo.
Update and prepare the Linux environment in WSL
After installing Ubuntu or your chosen distribution, it is a good idea to update the packages:
Open the terminal and runs:
sudo apt update && sudo apt upgrade -y
You can also install essential utilities:
sudo apt install git curl build-essential -y
These tools facilitate advanced development and scripting tasks.
Managing files and file systems between Windows and WSL
One of the main advantages of WSL is its full integration with Windows and Linux file systems.
- Access Windows disks from Linux: The units appear in
/mnt/(example:/mnt/cfor drive C:). - Open Explorer from WSL: Write
explorer.exe .to display the current directory in Windows.
To optimize performance, store your projects in the native file system:
- From Bash, save to
~o/home/usuario. - For editing with Windows tools, work in C: without any problems.
Getting Started with Bash: Basic Syntax and Scripting
Un script in Bash is a text file with commands written in Bash syntax. The usual extension is .sh, although it is not mandatory.
- Create a file with your favorite editor (nano, vim, code, etc):
nano mi_script.sh - Always include the shebang to indicate the interpreter:
#!/bin/bash - Add commands below, one per line. Example:
For example: echo "¡Hola, mundo!"
Save and close the editor.
Make the script executable with:
chmod +x mi_script.sh
Then run it with:
./mi_script.sh
You can also run it using Bash without prior permissions:
bash mi_script.sh
Fundamental elements of Bash scripts
Bash scripts allow you to automate complex tasks by combining commands and control structures.
- variables: They are assigned without prior declaration:
variable=valor. To use the value, use$variable. - Comments: They are indicated with
#. - Input and output:
read nombrerequests data from the user, andechoprints text or variables. - Conditionals: Just like
if,elifyelseSimple example:
if ; then echo "Eres mayor de edad"; fi - Loops:
for,whileycaseto repeat actions or make decisions. - Handling arguments: Access them with
$1,$2, etc.
Task Automation and Scheduling with Bash and WSL
Bash scripts can be scheduled to run automatically: using cron on Linux or Task Scheduler on Windows.
- With cron:
Runcrontab -eand add lines like:
0 0 * * * /home/usuario/miscript.shto run it every night at midnight. - Bash-Windows Interoperability: Usa
comando.exeto call Windows commands or run Bash from Windows with:
wsl bash -c "comando".
Advanced Optimization: Using Editors, Integrating with VS Code and Git
For complex projects, take advantage of advanced editors and version control.
- Visual Studio Code: Compatible with WSL via its "Remote – WSL" extension. Just install the extension and open it with
code .. - Go: install with
sudo apt install git, so you can clone repositories, make commits and manage versions without leaving Bash.
Work professionally from Windows, but with Linux tools.
Combining commands and practical examples with WSL
One advantage of WSL is the ability to mix Windows and Linux commands on a single line. Some useful examples:
- Display files with Linux from PowerShell:
wsl ls -la - Filter results:
wsl ls -la | findstr "git" - Edit files with Windows:
notepad.exe .bashrc - Export distribution:
wsl --export Ubuntu backup.tarywsl --import UbuntuNueva carpeta backup.tar
To see all available commands, use wsl --help.
Advanced management: disks, containers, databases, and GPUs
With WSL 2 you can mount external disks, manage Docker containers and use databases in your virtualized Linux environment.
- Mount discs or USB:
wsl --mount X: - Docker Support: Docker Desktop automatically integrates with WSL 2 to manage containers.
- Databases: Install servers like MySQL, PostgreSQL, or MongoDB directly on WSL for local development.
- GPU Acceleration: Take advantage of the GPU for intensive tasks if your hardware supports it.
Common tricks, debugging, and troubleshooting tips
Some common errors in Bash scripts in WSL can have simple solutions:
- Permission denied: Run
chmod +x script.sh. - Syntax or debugging errors: Add
set -xat startup or run withbash -x script.sh. - Problems with PATH: Add the routes to
~/.bashrcand recharge withsource ~/.bashrc. - Cron errors: Check out
/var/log/syslogto detect errors in scheduled tasks. - Failure in automated scripts: Usa
set -eto stop errors and avoid unwanted effects.
Mastering Bash scripting on Windows with WSL significantly expands your capabilities. The integration between the two systems allows you to seamlessly automate, manage, and enhance your work environment, leveraging the benefits of Linux and Windows in one place. Proper configuration, learning the core commands, and using editing and version control tools will help you achieve professional-level projects.
Passionate writer about the world of bytes and technology in general. I love sharing my knowledge through writing, and that's what I'll do on this blog, show you all the most interesting things about gadgets, software, hardware, tech trends, and more. My goal is to help you navigate the digital world in a simple and entertaining way.



