Can t run bash on windows 10

Download PC Repair Tool to quickly find & fix Windows errors automatically

Shell Scripts or .SH files are like batch files of Windows which can be executed in Linux or Unix. It is possible to run .sh or Shell Script file in Windows 10 using Windows Subsystem for Linux. In this post, we will show you how to run a Shell Script file in Windows 11/10.

Bash is a Unix shell and command language which can run Shell Script files. You do not need to install Ubuntu or any other Linux Distros unless your scripts need the support of the real Linux kernel. We will share both the methods.

  1. Execute Shell Script file using WSL
  2. Execute Shell Script using Ubuntu on Windows 10

1] Execute Shell Script file using WSL

Install WSL or Windows Subsystem for Linux

Go to Settings > Update & Security > For Developers. Check the Developer Mode radio button. And search for “Windows Features”, choose “Turn Windows features on or off”.

Scroll to find WSL, check the box, and then install it. Once done, one has to reboot to finish installing the requested changes. Press Restart now.  BASH will be available in the Command Prompt and PowerShell.

Execute Shell Script Files

  1. Open Command Prompt and navigate to the folder where the script file is available.
  2. Type Bash script-filename.sh and hit the enter key.
  3. It will execute the script, and depending on the file, you should see an output.

Can t run bash on windows 10

On a Linux platform, you usually use SH, but here you need to use BASH. That said, BASH in Windows has its limitations, so if you want to execute in a Linux environment, you need to install Ubuntu or anything similar.

2] Execute Shell Script using Ubuntu on Windows 11/10

Make sure you have Ubuntu or any other Linux distros installed.  Ubuntu will mount or make all your Windows directories available under /mnt. So the C drive is available at /mnt/C.  So if the desktop will be available at /mnt/c/users//desktop.

Can t run bash on windows 10

Now follow these steps

  1. Type Bash in run prompt, and it will launch the distro prompt.
  2. Navigate to the folder using “cd” command to the folder where the scripts are available.
  3. Type “sh script.sh” and hit Enter.

It will execute the script, and if they have a dependency on any of the core Linux features.

Since Linux is now available in Windows, you need not use any third-party applications like Cygwin. WSL should be enough for most of the scenarios to help you run a shell script in Windows 11/10.

How do I create a .SH file?

The steps to create a shell script file are:

  • Create a file using a editor
  • Name script file with extension . sh
  • Start the script with #! /bin/sh
  • Write the desired code
  • Save the script file as ABC.sh
  • For executing the script type bash ABC.sh.

Can you run shell scripts in Windows?

Yes, now with Bash Shell in Windows 11 and Windows 10, you can now create and run Bash shell scripts and incorporate Bash commands into a Windows batch file or PowerShell script.

Ashish is a veteran Windows and Xbox user who excels in writing tips, tricks, and features on it to improve your day-to-day experience with your devices. He has been a Microsoft MVP (2008-2010).

So, I've been using the new(ish) Bash on Ubuntu on Windows (WSL) for a while now and all has been top-notch, until yesterday.

I git-pushed from Bash by accident, so it asked me for my repo-destination account details like normal. I decided to ignore this, terminate Bash and try to just use powershell instead (can't ever remember passwords!). Terminating Bash however caused the shell to freeze. I forced closed and restarted my comp (I've had to force close and restart several times before for various reasons and everything was fine).

After boot up, I just tried to check if Bash was working again, but it wasn't. It just failed to start with no error message. For example:

PS C:\WINDOWS\system32> bash
PS C:\WINDOWS\system32>

Has anyone else had a similar situation/knows how to help?

EDIT: Only solved through reinstalling bash, using

    lxrun /uninstall /full

then

    lxrun /install 

asked May 18, 2017 at 13:26

oblongoblong

5752 gold badges5 silver badges8 bronze badges

2

I had the same issue but my solution was different. I found that my (Default) WSL distribution was set to docker-desktop-data instead of my Ubuntu distribution, e.g.

In PowerShell (Windows Shell): wslconfig /L

This lists WSL distributions. For me "docker-desktop-data (Default)" was listed as default not my Ubuntu distribution.

To change this:

In PowerShell (Windows Shell): wslconfig /setdefault Ubuntu-20.04

Can t run bash on windows 10

David Buck

3,61934 gold badges31 silver badges35 bronze badges

answered Jun 25, 2020 at 17:46

MarkMark

5214 silver badges2 bronze badges

4

Came here with a similar issue, but a different solution, so I'll post in case it helps anyone else.

The difference in my situation was that, when running bash through Command Prompt, it complained about Legacy Mode being enabled.

  1. Open a regular command prompt (win+r then cmd)
  2. Right-click the title bar and select Properties
  3. Deselect "Use legacy console (requires restart)"

Now it should work either by launching the standalone app, or typing bash into a regular cmd window after restarting Command Prompt.

This and other causes can be found in this Github issue.

answered Sep 11, 2017 at 1:19

Can t run bash on windows 10

Dave SDave S

7881 gold badge12 silver badges30 bronze badges

1

The solutions listed also did not work for me. I found a solution here.

Essentially, navigate to Control Panel > System > Advanced System Settings > Advanced > Settings > Advanced > Virtual memory, Change ..., and set a Custom size for the paging file size: 800 min and 1024 max. Restarted, and the command prompt came back.

answered Sep 30, 2018 at 5:19

Robert YiRobert Yi

1,1771 gold badge11 silver badges18 bronze badges

3

Do a FULL REBOOT. That worked for me. Windows 10 fast boots system to save memory. TO do a Full Reboot Hold Shift and Click on Restart/Shutdown.

answered May 5, 2020 at 10:21

Can t run bash on windows 10

0

I've had similar issues. The solution for me was to disable fast startup in powers settings.

answered Jun 11, 2019 at 23:03

0

Linux Distribution should be installed additionally to Windows Subsystem for Linux. See Install WSL on Windows 10 or Install WSL on Windows Server for detailed steps and explanations. In case mentioned manuals are moved or not available I'll put below main steps for Windows 10 that helped me:

  1. Open PowerShell as Administrator and run Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  2. Restart computer if prompted.
  3. Open PowerShell and run Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu.appx -UseBasicParsing
  4. Execute the downloaded Ubuntu.appx.
  5. Enjoy running bash on Windows again.

answered Apr 15, 2019 at 9:49

1

I had the same issue the following fix worked for me:

Fix:

  1. restart by clicking shift + restart button.
  2. it will load recovery options, just click on continue to windows.
  3. once pc starts open the terminal by start search for ubuntu click enter
  4. once terminal gets open it might show cursor blinking and does nothing.
  5. just press cntrl+c or cntrl+z and you will have problem solved.

answered Apr 23, 2020 at 14:28

Can t run bash on windows 10

See my comment to original poster. Your fix did not work for me. here is the PowerShell [as admin] listing: Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32> lxrun /uninstall /full
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore

This will uninstall Ubuntu on Windows.
This will remove the Ubuntu environment as well as any modifications, new applications, and user data.
Type "y" to continue: y
Uninstalling...
Error: 0x80070002
PS C:\WINDOWS\system32>

I went to https://aka.ms/wslstore

  • chose ubuntu
  • it downloaded
  • clicked 'pin to start'
  • clicked 'Launch'

Ubuntu [window]:

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: joe
Enter new UNIX password: joepw202

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: joe
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.

joe@joethinks:~$

Please note: BUMMER! None of my shortcuts or installs were moved over from my last version. Here i am running BASH from vscode:

To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.

joe@joethinks:/mnt/c/1d/TrinitySundayMusicPj$ cdtsm
cdtsm: command not found
joe@joethinks:/mnt/c/1d/TrinitySundayMusicPj$ cd trinitySundayMusic
joe@joethinks:/mnt/c/1d/TrinitySundayMusicPj/trinitySundayMusic$ node wizard.js
The program 'node' is currently not installed. You can install it by typing:
sudo apt install nodejs-legacy
joe@joethinks:/mnt/c/1d/TrinitySundayMusicPj/trinitySundayMusic$

At least it works.

answered May 26, 2018 at 19:29

4

Right after Windows Updates KBB4471324 and a reboot, Bash wouldn't launch. No messages.

In event viewer I saw messages about

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID

I didn't bother trying to figure out if the SID, CLSID and APPID were associated with bash.

I launched Bash as administrator, which worked, and then bash as a normal user, which worked. It seems to be fine, now.

answered Dec 15, 2018 at 21:54

Section i: other error messages.

  • This error is closely followed by a second error, code 0x80070057 (see section 2)!

  • This error also manifests as "Windows Subsystem for Linux has no installed distributions. Distributions can be installed by visiting the Microsoft Store: https://aka.ms/wslstore" by typing Bash at cmd/powershell. Use Section 1 then Section 2.

Section ii: verify your installation and restart.

Be sure that WSL (Windows Subsystem Linux) is checked/installed and your computer had a proper restart: {⊞START} → type "features" (ensure "Turn Windows features on or off" is selected). → {ENTER}. → Turn Windows Subsystem for Linux on. → Press OK. → Restart your computer immediately after the installation has finished.

Section 1a: Install Linux [via the Microsoft Store].

  1. Press {⊞START} on your keyboard.
  2. Type "store" ensure "Microsoft Store" is selected. → {ENTER}}.
  3. {SHIFT}-{TAB} twice (highlight search). → {ENTER}.
  4. type "subsystem". → {ENTER}.
  5. Select your flavor of Linux (i.e., "Ubuntu LTS 18.04") and click "Install".
  6. {⊞START}. -> Type "ubuntu" (ensure Ubuntu App is selected). → {ENTER}.

Section 1b: Side-load Linux.

*This is a placeholder--you can manually install WLS--https://learn.microsoft.com/en-us/windows/wsl/install-manual. I have not done this, yet. If you have done this, please add instructions by editing my answer; otherwise, I will post this section after performing this operation myself.

Section 2: if launching Ubuntu throws 'WslRegisterDistribution failed with error: 0x80070057'**

After installing a linux flavor:

  1. {⊞START} → type "features" (ensure "Turn Windows features on or off" is selected). → {ENTER}.
  2. Turn Windows Subsystem for Linux off. → Press OK.
  3. Turn Windows Subsystem for Linux on.
  4. Restart your computer.
  5. {⊞START}. → type "ubuntu" (ensure "Ubuntu App" is selected). → {ENTER}

**This is the most-accepted solution for this issue is the last answer on page two at Microsoft Answers.

answered Jan 4, 2020 at 20:42

Wolfpack'08Wolfpack'08

3,81810 gold badges45 silver badges78 bronze badges

What worked for me was to disable and enable WSL feature from control panel:

  1. Control Panel --> Programs and Features --> Turn Windows Feature on or off
  2. Uncheck "Windows Subsystem for Linux"
  3. Uninstall Ubuntu from Windows
  4. Restart
  5. In (1), check "Windows Subsystem for Linux"
  6. Install Ubuntu
  7. Success!

answered May 6, 2021 at 10:24

OrozcoOrozco

3352 silver badges8 bronze badges

If none of the previuos answers worked for you, try this workaround, after trying different alternatives, this one worked for me.

  1. Run windows + R
  2. type SystemPropertiesAdvanced
  3. click settings in performance group
  4. In advanced tab, deselect the automatically manage paging file size for all drives
  5. Select custom size and enter 800 for initial size, 1024 for maximum size.
  6. Apply changes and restart.

answered May 8, 2021 at 17:02

Why is Bash not running on Windows 10?

This error occurs due to the “Windows Subsystem for Linux” not running on the C drive, which is Windows's system drive. To address this issue, ensure that your Linux system is installed in the C drive.

Why does Bash not work on Windows?

If the build version is less than 14393, you will not be able to install Bash. To enable Bash on a supported build, you should first turn on Developer Mode. To do so, head over to Settings, click on For Developers and select the Developer Mode radio button.

Why is my Bash not working?

In short, look for the following to fix “ bash: bashtop: command not found “: Make sure the shell PATH variable correctly set and verify your PATH environment variable. Verify that the file you want to execute or run exists on the Unix or Linux box. Some commands need to run as the superuser (root user).

How to install Bash shell in Windows 10?

What to Know.
Developer Mode: Right-click Start menu > select Settings > Update & Security > For developers..
Next: Select Developer mode > Yes > enable Windows Subsystem For Linux > restart..
Use bash: Right-click Start menu > select Windows PowerShell (Admin) > type "bash" > press Enter..