How to Execute Shell Script Files on Windows 10 Using WSL.
Bash is a Unix shell and command language which can run Shell Script files.
- Execute Shell Script file using WSL
- Execute Shell Script using Ubuntu on Windows 10
Execute Shell Script file using WSL
Install WSL or Windows Subsystem for Linux
1. Go to Settings\Update & Security\For Developers. Check the Developer Mode;
2. Search for Windows Feature, and choose to Turn Windows features on or off;
3. Scroll to find WSL, check the box, and then install it;
4. Reboot to finish installing the requested changes;
5. BASH will be available in the Command Prompt and PowerShell.
Execute Shell Script Files
1. Open Windows PowerShell and navigate to the folder where the script file is available;
2. Type:
Bash script-filename.sh
It will execute the script, and depending on the file, you should see an output.
On a Linux platform, you usually use SH, but here you need to use BASH.
Execute Shell Script using Ubuntu in dual-boot
Make sure you have Ubuntu or any other Linux distros installed on the target PC in dual-boot with Windows 10. Ubuntu will mount or make all your Windows directories available under /mnt. So the C:\ drive is available at /mnt/C.
Now follow these steps:
- Type Bash in a run prompt, and it will launch the distro prompt.
- Navigate to the folder using the cd command to the folder where the scripts are available.
- Type sh script.sh and hit enter.
This is false, to use bash like this you NEED to have linux distribution installed