I'm hoping someone can help as my windows scripting skills are poor and I'm struggling to get this to work.
From foobar2000 windows I'm trying to call a bash script (using WSL) passing the path of the music file that's selected in the interface, but I'm struggling to deal with & in directory names.
Current approach
[Run services] I'm using a .bat file as I can't get foo_run to start a 64 bit cmd window in order to start bash so I have some necessary redirection here
cmd.exe /k "d:\test.bat "$substr(%_path%,0,$strrchr(%_path%,'\'))""
[test.bat]
"%WINDIR%\sysnative\cmd.exe" /k bash /mnt/d/test.sh '%~1'
[test.sh] (Obviously I'll do something more useful here when it's working)
#!/bin/bash
targetDir=`wslpath -a "$1"`
cd "$targetDir"
pwd
ls -al
If the path doesn't have an ampersand in it, it works, otherwise it throws:
C:\Program Files (x86)\_personalInstalls\foobar2000>"C:\Windows\sysnative\cmd.exe" /k bash /mnt/d/test.sh 'G:\Tagged & Cleaned\flac\Adams, Bryan\2012 - Cuts Like A Knife\'
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
Notice the folder is actually 'Tagged&Cleaned', I'm guessing the step that passes it to bash is evaluating it somehow, but I don't know why, and I've tried lots of quoting variations but I just can't get it to work.
Hopefully it's a simple fix....