I'm having trouble writing a program that takes the /path/to/file in an WSL Ubuntu environment and opens that file in its default Windows program. The biggest issue here is converting the /path/to/file/for/WSL into a path\to\file\for\windows. This is what I wrote and put in my .bashrc file:
# Function to get open-wsl to work
function open-from-wsl() {
echo "opening"
cmd_directory = echo "$1" | sed 's/^\///' | sed 's/\//\\/g' | sed 's/^...../\0C:/' | sed 's/^\mnt//'
cmd_directory = echo "$cmd_directory" | sed 's/^..//'
cmd.exe /C start $cmd_directory
}
Ideally what this is supposed to accomplish is if I type :
open-from-wsl /mnt/c/Users/DavidG/Google\ Drive/folder/file.PDF
I'll have my file.PDF open in my default PDF viewer. As of right now however, I get the error cmd_directory: command not found and then my command prompt window opens up. This of course is being written so that I can open any file from WSL and have it open in it's default program, it doesn't just pertain to PDFs.
EDIT: I've adjusted the code like so thanks to Socowi's input:
# Function to get open-wsl to work
function open-from-wsl() {
echo "opening"
cmd_directory=$(echo "$1" | sed 's#\##')
cmd_directory=$(echo "$cmd_directory" | sed 's/^\///' | sed 's/\//\\/g' | sed 's/^...../\0C:/' | sed 's/^\mnt//')
cmd_directory=$(echo "$cmd_directory" | sed 's/^..//')
cmd.exe /C start $cmd_directory
}
My issue now seems to be that I can't remove the \ from /mnt/c/Users/DavidG/Google\ Drive/folder/file.PDF, which was my goal by adding the line
cmd_directory=$(echo "$1" | sed 's#\##')
=and encapsulateecho ... | sed ... | ...in$().