Kaitkan .SH Shell Script dengan Bash di Windows 10

Jika Anda telah menginstal Bash di Ubuntu pada Windows di Windows 10 versi 1607 dan lebih tinggi, dan ingin mengaitkan skrip shell .SH dengan Bash, berikut adalah solusi skrip cepat.

Untuk mengakses jalur sistem file Windows di Bash, Anda menggunakan sintaks atau semantik berikut:

 /mnt/c/Windows/MyTasks.sh 

Saya menulis Vbscript kecil yang mengubah jalur file Windows seperti C:\Windows\MyTasks.sh, menjadi * NIX path system file. Script kemudian meluncurkan Bash melewati jalur file * NIX sebagai argumen. Skrip ini dapat dikaitkan dengan tipe file .SH menggunakan suntingan registri yang disertakan bersama ini.

Unduh

Unduh bash_sh_assoc.zip, unzip dan jalankan file REG terlampir. Kemudian pindahkan file script bash.vbs ke direktori Windows. Ini mengaitkan tipe file .SH dengan file skrip bash.vbs.

Isi dari file Vbscript 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 

Isi dari file REG

 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\"" 

Posting terkait

Tambahkan Bash ke Menu Klik Kanan untuk Folder di Windows 10

Artikel Terkait