How to use start command in bash on Windows
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).
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"
}
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 pressCtrl-C
to cancel.- Perhaps the function can be enhanced to take care of this edge case. I leave that to you as an exercise.