Verknüpfen von Linux-Shell-Skripts (.sh) unter Windows 10 mit Bash oder WSL

5568
Alex Sim

Wenn Sie jemals versucht hatten, ein .sh-Linux-Skript durch Doppelklicken auf Windows 10 auszuführen, nachdem Sie es standardmäßig bash.exe (Ubuntu Bash für Windows 10) zugewiesen hatten, bemerkten Sie höchstwahrscheinlich, dass es nicht geöffnet wurde.

Warum öffnet es sich nicht und wie kann ich das beheben?

0

1 Antwort auf die Frage

2
Alex Sim

BEARBEITEN: Der Registrierungsschlüssel und die folgenden Informationen sind OBSOLETE. Informationen hierzu finden Sie in der neuen Version: Kann ich Dateien mit Bash unter Ubuntu unter Windows oder Windows Subsystem for Linux (WSL) in ein .sh-Skript ziehen und ablegen ?

Dies kann durch Bearbeiten eines einzelnen Registrierungsschlüssels (oder mehr für zusätzliche Funktionen) erfolgen.

Ich werde natürlich eine .reg-Datei (eigentlich drei gezippte reg-Dateien) verlinken, um die Problemumgehung (zusammen mit der Symbolzuordnung und dem (optionalen) Nano-Editier-Enabler) schnell zu installieren, ohne die Registrierung selbst bearbeiten zu müssen muss nur Schritt 1 folgen;

FILE (only follow step 1, then download and install): http://www.mediafire.com/file/r5uxk9c0hhucvt9/ShellBashScriptOpen_v3.rar

But to satisfy your healthy mistrust, here is how you can do it yourself:

.

1) Set bash.exe as default program for .sh files

Just right-click an sh file, go to properties, locate "open with", change > more_apps > find_an_app_in_this_PC and select C:\Windows\System32\bash.exe;

Apply and you are good to go.

.

2) Actual double-click to open key

create the following registry key with regedit

HKEY_CLASSES_ROOT\Applications\bash.exe\shell\open\command 

a) If you want to keep bash open after script finished

set the (Default) value to

"C:\Windows\System32\bash.exe" -c " \"./$(grep -oE '[^\\]+$' <<< '%L')\"; cd ~; bash;" 

b) If you want to close bash after script finished

set the (Default) value to

"C:\Windows\System32\bash.exe" -c " \"./$(grep -oE '[^\\]+$' <<< '%L')\";" 

.

3) Open as admin option

create the following registry key with regedit

HKEY_CLASSES_ROOT\Applications\bash.exe\shell\runas\command 

a) If you want to keep bash open after script finished

set the (Default) value to

"C:\Windows\System32\bash.exe" -c " sudo bash \"$(grep -oE '[^\\]+$' <<< '%L')\"; cd ~; bash" 

b) If you want to close bash after script finished

set the (Default) value to

"C:\Windows\System32\bash.exe" -c " sudo bash \"$(grep -oE '[^\\]+$' <<< '%L')\";" 

.

4) Assign default icon key (optional [but cooler])

create the following registry key

HKEY_CLASSES_ROOT\Applications\bash.exe\DefaultIcon 

and set the (Default) value to

%USERPROFILE%\AppData\Local\lxss\bash.ico,0 

.

5) Add right-click > edit option (with nano editor) (optional)

create the following registry key

HKEY_CLASSES_ROOT\Applications\bash.exe\shell\edit\command 

and set the (Default) value to

"C:\Windows\System32\bash.exe" -c "nano -miST 4 \"$(grep -oE '[^\\]+$' <<< '%L')\""