0

I'm using this method to have .sh files in Windows Explorer execute using bash.exe:

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

This works fine for files outside of my WSL2 linux distro, however for files such as \\wsl$\Ubuntu\home\davidg\example.sh I get Permission denied.

From powershell I can run bash.exe ./example.sh from the working directory and it executes no problem.

Why is this happening and how can I resolve it?

UPDATE: Workaround is to run pushd \\wsl$\Ubuntu from cmd.exe and execute the .sh files from the mapped drive in Windows Explorer instead of the UNC path.

  • What do you want to do with the first command? What is the "working directory" here? – Biswapriyo Dec 27 '19 at 8:59
  • @Biswapriyo That's added to the requisite regedit key (see link from OP). %L I believe is the full path to the target so that command extracts the filename and prepends ./. The working directory ends up being the directory of the target .sh file ie `\\wsl$\Ubuntu\home\davidg` in this example. – davegravy Dec 27 '19 at 14:39
0

This seems to work, though I'm not entirely sure why:

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

From what I can tell the outer call to bash is necessary to be called with -c, since there's a sequence of commands. Making the call to the .sh file benefited from an inner bash call with no command line options (ie passing only a reference to a file with shell commands per the manpage).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.