{"id":3751,"date":"2016-08-09T17:52:03","date_gmt":"2016-08-09T12:22:03","guid":{"rendered":"http:\/\/198.58.113.91\/blog\/?p=3751"},"modified":"2019-05-12T02:54:25","modified_gmt":"2019-05-12T02:54:25","slug":"sh-files-associate-with-bash-windows-10","status":"publish","type":"post","link":"https:\/\/www.winhelponline.com\/blog\/sh-files-associate-with-bash-windows-10\/","title":{"rendered":"Associate .SH Shell Scripts with Bash in Windows 10"},"content":{"rendered":"<p>If you&#8217;ve installed <a target=\"_blank\" href=\"https:\/\/blogs.msdn.microsoft.com\/commandline\/2016\/04\/06\/bash-on-ubuntu-on-windows-download-now-3\/\" rel=\"noopener noreferrer\">Bash on Ubuntu on Windows<\/a> in Windows 10 version 1607 and higher, and want to associate .SH shell scripts with Bash, here is a quick script solution.<!--more--><\/p>\n<p>To access Windows file system path in Bash, you use the following syntax or semantics:<\/p>\n<pre>\/mnt\/c\/Windows\/MyTasks.sh<\/pre>\n<p>I wrote a small Vbscript that converts the Windows file path such as <code>C:\\Windows\\MyTasks.sh<\/code>, 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.<\/p>\n<h2>Download<\/h2>\n<p>Download <a href=\"https:\/\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/bash_sh_assoc.zip\">bash_sh_assoc.zip<\/a>, unzip and run the enclosed REG file. Then move the script file <code>bash.vbs<\/code> to the Windows directory. This associates .SH file types with bash.vbs script file.<\/p>\n<h2>Contents of the Vbscript file Bash.vbs<\/h2>\n<pre><code>If WScript.arguments.count  0 then\r\n\tsSHfile = WScript.Arguments(0)\r\n\tIf LCase(Right(sSHfile, 3)) = \".sh\" Then\r\n\t    Dim WshShell: Set WshShell = WScript.CreateObject(\"Wscript.Shell\")\r\n\t    PathArr = Split(sSHfile, \":\")\r\n\t    sSHfile = \"\/mnt\/\" &amp; LCase(PathArr(0)) &amp; PathArr(1)\r\n\t    sSHfile = Replace(sSHfile,\"\\\",\"\/\")\r\n\t    WshShell.Run \"%systemroot%\\system32\\bash.exe \" &amp; \"\"\"\" &amp; sSHfile  &amp; \"\"\"\",,True\r\n\t    Set WshShell = Nothing\r\n\tEnd If\r\nEnd If<\/code><\/pre>\n<h2>Contents of the REG file<\/h2>\n<pre><code>Windows Registry Editor Version 5.00\r\n\r\n[HKEY_CLASSES_ROOT\\.sh]\r\n@=\"shfile\"\r\n\r\n[HKEY_CLASSES_ROOT\\shfile]\r\n@=\"SH Script File\"\r\n\r\n[HKEY_CLASSES_ROOT\\shfile\\defaulticon]\r\n@=\"%USERPROFILE%\\\\AppData\\\\Local\\\\lxss\\\\bash.ico\"\r\n\r\n[HKEY_CLASSES_ROOT\\shfile\\shell\\open\\command]\r\n@=\"wscript.exe \\\"C:\\\\Windows\\\\bash.vbs\\\" \\\"%1\\\"\"\r\n<\/code><\/pre>\n<h2>Related post<\/h2>\n<p><a href=\"https:\/\/www.winhelponline.com\/blog\/add-bash-right-click-menu-folders-windows-10\/\">Add Bash to the Right-Click Menu for Folders in Windows 10<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[64,480],"class_list":["post-3751","post","type-post","status-publish","format-standard","hentry","category-windows-10","tag-bash","tag-scripts"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3781,"url":"https:\/\/www.winhelponline.com\/blog\/bash-does-not-start-unsupported-console-settings-windows-10\/","url_meta":{"origin":3751,"position":0},"title":"Bash does not start &#8211; Error &#8220;Unsupported console settings&#8221; in Windows 10","author":"Ramesh","date":"August 31, 2016","format":false,"excerpt":"When you try to launch Bash.exe (Bash on Ubuntu on Windows) in Windows 10, the console window may open and close immediately. This happens if legacy mode is turned on for Command Prompt.Also, if you open a Command Prompt window and type bash.exe, the following error would show up:Unsupported console\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"bash command prompt legacy mode error","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/cmd-prompt-legacy-mode.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18617,"url":"https:\/\/www.winhelponline.com\/blog\/open-file-folder-path-clipboard-using-shortcut\/","url_meta":{"origin":3751,"position":1},"title":"How to Open File or Folder Path from the Clipboard Using Shortcut","author":"Ramesh","date":"September 15, 2020","format":false,"excerpt":"Sometimes we may need to copy a file or folder path from your email or chat window to the clipboard, and open the file or folder manually. Most people open the file or folder by launching the Run dialog, pasting the path from the Clipboard, and clicking OK. If your\u2026","rel":"","context":"In &quot;Utilities&quot;","block_context":{"text":"Utilities","link":"https:\/\/www.winhelponline.com\/blog\/category\/utilities\/"},"img":{"alt_text":"copy path to clipboard to Run dialog","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2020\/09\/copy-path-clipboard-run-dialog.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3721,"url":"https:\/\/www.winhelponline.com\/blog\/add-bash-right-click-menu-folders-windows-10\/","url_meta":{"origin":3751,"position":2},"title":"Add Bash to the Right-Click Menu for Folders in Windows 10","author":"Ramesh","date":"August 13, 2016","format":false,"excerpt":"So you installed Bash in Windows 10 (Anniversary Update v1607) and wondering how to add it to the right-click menu for folders, like the built-in \"Open Command window here\" option? Here is a registry edit to add \"Bash here\" to the context menu for folders and desktop.Download bash_here.zip and run\u2026","rel":"","context":"In &quot;Windows 10&quot;","block_context":{"text":"Windows 10","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/windows-10\/"},"img":{"alt_text":"add bash right-click menu","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/bash-here-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/bash-here-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/bash-here-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":185,"url":"https:\/\/www.winhelponline.com\/blog\/vbscript-files-open-with-notepad\/","url_meta":{"origin":3751,"position":3},"title":"[Fix] VBScript Files Open With Notepad","author":"Ramesh","date":"April 16, 2008","format":false,"excerpt":"When you try to run a VBScript by double-clicking it, the script may open in Notepad. This happens if the user has set Notepad as the default (instead of wscript.exe) program for .vbs files, using Open with or through any other methods.. [Fix] VBScript Files Open With Notepad Running VBScript\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"vbs files open in notepad","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/04\/vbsopen.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/04\/vbsopen.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2008\/04\/vbsopen.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3903,"url":"https:\/\/www.winhelponline.com\/blog\/copy-as-path-without-quotes-file-uri-format\/","url_meta":{"origin":3751,"position":4},"title":"How to Copy as Path Without Quotes or in File URI Format","author":"Ramesh","date":"August 26, 2016","format":false,"excerpt":"When using the built-in Copy as Path context menu option or the Copy Path ribbon button to copy file names to clipboard, the output would contain quotes for file\/folder name paths, such as below. There are some situations where you don't need quotes whether the file names contain spaces or\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"copy as path without quotes and in URI format","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/copyaspath-uri-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/copyaspath-uri-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/2016\/08\/copyaspath-uri-1.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1954,"url":"https:\/\/www.winhelponline.com\/blog\/associate-autocad-script-scr-notepad-screen-saver\/","url_meta":{"origin":3751,"position":5},"title":"How to Associate AutoCAD Script (.SCR) Files With Notepad?","author":"Ramesh","date":"March 9, 2016","format":false,"excerpt":"AutoCAD Script files and Windows Screen Savers, both use .SCR file extension. If you're trying to change the .SCR file type association to edit your AutoCAD scripts with Notepad or any other editor, you'll note that the Open With... right-click menu option isn't available for .SCR files. That's because they're\u2026","rel":"","context":"In &quot;Windows&quot;","block_context":{"text":"Windows","link":"https:\/\/www.winhelponline.com\/blog\/category\/microsoft\/windows\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.winhelponline.com\/blog\/wp-content\/uploads\/w10\/autocad-scr.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/3751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/comments?post=3751"}],"version-history":[{"count":0,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/posts\/3751\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/media?parent=3751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/categories?post=3751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winhelponline.com\/blog\/wp-json\/wp\/v2\/tags?post=3751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}