cygpath inconsistent with variable as input unix to windows conversion

519 Views Asked by At

I have a bash script that prompts a user to drag and drop a file as an input and then I need to convert that path to windows style path so I can use it as an argument to an .exe that is being called:

echo -e "\nPlease drag and drop your input audio file into this window and hit Enter\n"
read inputfile

inputfilewin=$(cygpath -w -a "${inputfile}")

echo "inputfile: $inputfile"
echo "inputfilewin: $inputfilewin"

This works fine for paths with no spaces but my Box Sync folder produces a response like this:

C:\cygwin\home\jimbob\'\cygdrive\c\Users\jimbob\Box Sync\myscripts\testscript\6ch.wav'

but if i just type on the command line cygpath -w -a and drag and drop the same file i get the right path back:

C:\Users\jimbob\Box Sync\myscripts\testscript\6ch.wav

Please help I just can't get it to work how I need

1

There are 1 best solutions below

2
On
$ echo  $a
/cygdrive/c/Program Files/Autodesk/DWG TrueView 2016 - English

so depending on how many escape you need:

$ cygpath  -w "$(echo -n $a |sed -e 's/ /\ /g')"
C:\Program Files\Autodesk\DWG TrueView 2016 - English

$ cygpath  -w "$(echo -n $a |sed -e 's/ /\\ /g')"
C:\Program\ Files\Autodesk\DWG\ TrueView\ 2016\ -\ English