1

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

jwsmite
  • 11
  • 1

1 Answers1

0
$ 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
matzeri
  • 8,062
  • 2
  • 15
  • 16
  • Thanks for the reply, I still get this bit at the start though: `C:\cygwin\home\jsmit\'\cygdrive\c\Users\jimbob\`` I'm using this in the script: `inputfilewin=$(cygpath -w -a "$(echo -n $inputfile | sed -e 's/ /\\ /g')")` – jwsmite May 12 '16 at 14:53
  • what is the output of `echo ${inputfile}` ? – matzeri May 12 '16 at 15:50