Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable bash commands in Windows CMD?

I've two Windows machines and both have bash installed. However, they differ in the way bash starts up:

Machine 1:

Typing "bash" starts the bash. Then I can type commands like ls.

Machine 2:

It seems like it starts bash and directly runs ls in it, by only typing "ls". After that it switches back to CMD automatically, like this:

like this

Does anyone know which setting enables the behavior of machine 2? Everything looks the same for me. It's a nice feature and I want to enable it on machine 1 as well.

like image 771
nejckorasa Avatar asked Jan 20 '17 11:01

nejckorasa


2 Answers

Bash on Ubuntu on Windows executables (binaries) cannot run from Windows applications such as cmd.exe or PowerShell.exe - Windows doesn't even see them as executable.

The likeliest explanation is that you've installed a separate Unix emulation environment such as GnuWin, which comes with native Windows binaries.

To see the location of your - by definition Windows-native - ls executable, run where ls, which will probably tell you what product it came with, such as
C:\Program Files (x86)\GnuWin32\bin\ls.EXE.

Note that the Ubuntu on Windows binaries are stored in a user-specific manner in
%LOCALAPPDATA%\lxss\rootfs\bin, but that is a moot point, given that you cannot invoke them from Windows.

like image 104
mklement0 Avatar answered Sep 23 '22 18:09

mklement0


In Windows 10, there is a built-in Linux subsystem (one of the greatest features of Windows 10). It gives you almost a complete Linux shell for various distributions, and you can almost do anything with it (user mode).

I bet it is installed on your first computer, and you are using that subsystem. In the latest version of this subsystem, you can run both Linux executables and Windows exe files.

like image 42
Afshin Avatar answered Sep 23 '22 18:09

Afshin