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:
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 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\""
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!
About the author
Ramesh Srinivasan founded Winhelponline.com back in 2005. He is passionate about Microsoft technologies and has a vast experience in Windows — delivering support for Microsoft's consumer products. He has been a Microsoft MVP (2003-2012) who contributes to various Windows support forums.