I am trying to write a script to automate installing some things in WSL and then cloning a repo to the user's home folder in Windows (e.g. C:/Users/Frank/).
To do this I need to get the Windows username (e.g. Frank) to know where to cd to. I found that I could execute Windows command line commands with cmd.exe /c '<command>' and that the command echo %USERNAME% outputs the Windows user's username.
This is what I've tried so far:
#!/bin/bash
USER_NAME=`cmd.exe /c 'echo %USERNAME%'`
cd /mnt/c/Users/$USER_NAME
pwd
I get an error that I believe stems from the Windows carriage return characters \r which I guess are at the end of the output of echo %USERNAME%.
The error:
ine 3: cd: $'/mnt/c/Users/Frank\r\r\r': No such file or directory
How can I remove all of the \r characters at the end of the output?