5

I want to use Windows' start command in bash on Ubuntu on Windows (i.e., WSL). However, I couldn't use it by simply typing start:

nek@NEK:/mnt/c/Users/Nek$ start test.txt
Command 'start' is available in '/sbin/start'
The command could not be located because '/sbin' is not included in the PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with your user account.
start: command not found

And I noticed that start.exe might not exist.

C:\Users\Nek>where start
INFO: Could not find files for the given pattern(s).

Is start a builtin command? Can we use start in bash?

Environment

  • Windows 10 build 14393.693 (Update: This version is old for executing .exe files on bash. I should update Windows build >= 14951, and then follow the answer.)
  • Bash on Ubuntu on Windows (bash 4.3.11(1)-release x86_64-pc-linux-gnu, Ubuntu 14.04)

Related Links

nekketsuuu
  • 175
  • 1
  • 2
  • 9

3 Answers3

11

Is start a builtin command?

Yes.

Internal commands

The Windows CMD shell CMD.exe contains a number of 'internal' commands, additional 'external' commands are also supplied as separate executable files. External commands are generally stored in the C:\WINDOWS\System32 folder, this folder is part of the system PATH .

This arrangement means that both internal and external commands are always available no matter what your current directory happens to be.

ASSOC, BREAK, CALL ,CD/CHDIR, CLS, COLOR, COPY, DATE, DEL, DIR, DPATH, ECHO, ENDLOCAL, ERASE, EXIT, FOR, FTYPE, GOTO, IF, KEYS, MD/MKDIR, MKLINK (vista and above), MOVE, PATH, PAUSE, POPD, PROMPT, PUSHD, REM, REN/RENAME, RD/RMDIR, SET, SETLOCAL, SHIFT, START, TIME, TITLE, TYPE, VER, VERIFY, VOL

Source syntax-internal


Can we use start in bash?

Yes. Start a command shell and run the start command.

Example:

cmd.exe /c start "" test.txt

If this doesn't work specify the full path as follows:

/mnt/c/Windows/system32/cmd.exe /c start "" test.txt

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • cmd - Start a new CMD shell and (optionally) run a command/executable program.
  • start - Start a program, command or batch script (opens in a new window).
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • Thanks for your answer, but the command `cmd` is not found on bash. Am I missing something? (Currently, I doubt whether build version is old.) – nekketsuuu Feb 24 '17 at 12:25
  • @nekketsuuu You need to add `.exe` Try using `cmd.exe ...` or specify the full path `/mnt/c/Windows/system32/cmd.exe ...`. Answer updated. – DavidPostill Feb 24 '17 at 12:28
  • Maybe system32 -> System32 – nekketsuuu Feb 24 '17 at 12:32
  • @nekketsuuu That shouldn't make a difference, it is the `.exe` that is important. `bash` doesn't know how to execute files if you don't add `.exe` to the command name. – DavidPostill Feb 24 '17 at 12:35
  • That is all explained in your second link ... – DavidPostill Feb 24 '17 at 12:36
  • 1
    In my trial, `/mnt/c/Windows/system32/cmd.exe ...` caused a bash error `No such file or directory`, and `/mnt/c/Windows/System32/cmd.exe ...` caused `cannot execute binary file: Exec format error`. So I'll update Windows Insider Build and try again. Anyway, Thank you for your answer! – nekketsuuu Feb 24 '17 at 12:54
  • @nekketsuuu Do you need more help? If this answered your question, please don't forget to [accept the answer](http://superuser.com/help/accepted-answer). – DavidPostill Feb 24 '17 at 12:55
  • I'll mark this after it succeeds. Please wait for it :-) – nekketsuuu Feb 24 '17 at 12:59
  • This successfully works on Windows 10 Build 15063.13! Thanks a lot! – nekketsuuu Apr 12 '17 at 01:02
  • 2
    Thanks; I added `alias open='cmd.exe /c start ""' ` to my `.bashrc`. – dimo414 May 26 '17 at 04:06
  • **In WSL2,** this only works for directories in the Windows file system. If you run it for any Linux directory, you get the warning `UNC paths are not supported. Defaulting to Windows directory.` and sure enough the File Explorer opens up with `C:\Windows`. PowerShell's `Start-Process` supports UNC paths. – ADTC Jun 17 '21 at 17:33
4

In other answers, cmd.exe is suggested. However, the Command Prompt does not support UNC paths. The Linux file system in WSL2 is represented as UNC paths in Windows.

In this case, the better alternative is PowerShell. Borrowing from Alex G's function, it is re-written as:

function start {
  abspath=$(readlink -f "$1");
  wpath=$(/bin/wslpath -w "$abspath");
  powershell.exe -Command Start-Process "$wpath"
}

If you have disabled the addition of Windows PATH by adding [interop] appendWindowsPath = false to /etc/wsl.conf, then use the absolute path gotten by where powershell.exe:

function start {
  abspath=$(readlink -f "$1");
  wpath=$(/bin/wslpath -w "$abspath");
  /mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0//powershell.exe -Command Start-Process "$wpath"
}

Add this to your .bashrc to make sure you have it in every session.

Usage:

  • start . - Opens the current directory in Windows File Explorer.
  • start /any/linux/path - Opens the Linux directory as a UNC path.
  • start /mnt/c/any/windows/path - Opens the Windows folder as a regular path.
  • start - Forces the PowerShell command to prompt you for a path. Type one in, such as . or a Windows/UNC path (Linux paths won't work here) or press Ctrl-C to cancel.
    • Perhaps the function can be enhanced to take care of this edge case. I leave that to you as an exercise.
ADTC
  • 2,954
  • 3
  • 30
  • 49
3

The above answer didn't work for me - cmd.exe is expecting a windows path (C:\this\that) rather than a linux path. The following shell function got me up and running:

function start {
    abspath=$(readlink -f "$1");
    wpath=$(/bin/wslpath -w "$abspath");
    /c/Windows/System32/cmd.exe /c start "" "$wpath"
}
Alex G
  • 131
  • 2
  • 1
    Wrong syntax - should replace `'$@'` to `"$1"` (Note the double quote. And wslpath can only process one file argument) – Johnny Wong Oct 31 '19 at 06:37
  • Thanks @JohnnyWong - I've made some edits that get around the quoting problem (not easy to nest double-quotes) and use the correct input var. – Alex G May 20 '20 at 00:03
  • 1
    **In WSL2,** it should be `/mnt/c/...`. Unfortunately it only works for folders in the Windows file system, not the ones in Linux (since they are UNC paths). We should use PowerShell's `Start-Process` instead if UNC paths should be supported. – ADTC Jun 17 '21 at 17:36