If you’ve installed Bash on Ubuntu on Windows in Windows 10 version 1607 and higher, and want to associate .SH shell scripts with Bash, here is a quick script solution.
To access Windows file system path in Bash, you use the following syntax or semantics:
/mnt/c/Windows/MyTasks.sh
I wrote a small Vbscript that converts the Windows file path such as C:\Windows\MyTasks.sh
, to *NIX file system path. The script then launches Bash passing the *NIX file path as the argument. This script can be associated with .SH file types using the registry edit supplied herewith.
Download
Download bash_sh_assoc.zip, unzip and run the enclosed REG file. Then move the script file bash.vbs
to the Windows directory. This associates .SH file types with bash.vbs script file.
Contents of the Vbscript file Bash.vbs
If WScript.arguments.count 0 then
sSHfile = WScript.Arguments(0)
If LCase(Right(sSHfile, 3)) = ".sh" Then
Dim WshShell: Set WshShell = WScript.CreateObject("Wscript.Shell")
PathArr = Split(sSHfile, ":")
sSHfile = "/mnt/" & LCase(PathArr(0)) & PathArr(1)
sSHfile = Replace(sSHfile,"\","/")
WshShell.Run "%systemroot%\system32\bash.exe " & """" & sSHfile & """",,True
Set WshShell = Nothing
End If
End If
Contents of the REG file
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.sh]
@="shfile"
[HKEY_CLASSES_ROOT\shfile]
@="SH Script File"
[HKEY_CLASSES_ROOT\shfile\defaulticon]
@="%USERPROFILE%\\AppData\\Local\\lxss\\bash.ico"
[HKEY_CLASSES_ROOT\shfile\shell\open\command]
@="wscript.exe \"C:\\Windows\\bash.vbs\" \"%1\""
Related post
Add Bash to the Right-Click Menu for Folders in Windows 10
One small request: If you liked this post, please share this?
One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!
ERROR:
The .reg file in the bash_sh_assoc.zip download does not match the contents shown above and will not work. Looks like it was the author’s development copy.
The vbs file only differs in the use of %systemroot% instead of %windir%, which makes difference.
Thanks for the heads up. I’ve updated the script path in the REG file. Regarding the script, %windir% simply refers to %systemroot% – so both things work. I’ll update the post for uniformity.