0

I am running an .sh script from wsl bash.
Inside the script I want capture a file path, into a variable, in order to pass it to cmd.exe like so:

my_win_path=<some_windows_unc_path_to_executable>
cmd.exe /c "$my_win_path"

However when I try to capture the file path, it's backslashes are getting formatted, resulting in an non-valid path.

Example:

~: wslpath -w .
C:\tmp
~: var=$(wslpath -w .); echo $var
C:      mp
cmd.exe /c "$var # will error

How do I capture the output of wslpath into a valid variable without formatting the escape characters ?

(I hope I am using the right terminology here. Please correct me if not.)

sogrady
  • 1
  • 2
  • Can you post error messages ? – Philippe Aug 30 '22 at 21:56
  • I don't know what you want to achieve: Show the content of `var` using the command `echo -nE $var|xxd`, and explain which part of the content you want to remove. – user1934428 Aug 31 '22 at 09:20
  • @Philippe it probably would have been something like `... is not recognized as an internal or external command` – sogrady Sep 20 '22 at 17:08
  • I must have gotten confused by the default `echo` output. This actually worked fine: ```shell ~: wslpath -w ~/c/Python37/python.exe C:\Python37\python.exe ~: python_exe=$(wslpath -w ~/c/Python37/python.exe);echo $var # or echo -nE $var C:\Python37\python.exe cmd.exe /c "$python_exe ``` Thanks @user1934428 , @Philippe – sogrady Sep 20 '22 at 17:11
  • @sogrady : Don't put that much code in a comment. It's hard to read. Amend your question with properly formatted code. – user1934428 Sep 30 '22 at 09:33

0 Answers0