0

I'm trying to set my HOME path in Windows 10:

setx -m HOME C:\Users\MyName

Then I check the variable's value:

echo %HOME%

and it returns

c:UsersMyName

This is a pain, since I'm trying to use Git with ssh and it needs to know the home folder where my .ssh folder is stored. What am I doing wrong?

Stromael
  • 168
  • 1
  • 9
  • Does `setx -m HOME %USERPROFILE%` work? or `setx -m HOME "C:\Users\MyName"` –  Jun 14 '21 at 07:00
  • 1
    if you need to use `setx` then probably you're doing it wrong. `setx` is used to set a variable permanently so it should be done once only, and can be replaced by other methods like editing the registry. Besides you don't need `%HOME%` because there's already `%USERPROFILE%` – phuclv Jun 14 '21 at 07:23

1 Answers1

1

Probably you're calling setx from bash. Since \ is an escape character in bash and most other Unix shells, it won't result in a literal backslash. You need to escape the backslash itself with \ or quote it with ':

$ echo setx -m HOME C:\Users\MyName
setx -m HOME C:UsersMyName
$ echo setx -m HOME 'C:\Users\MyName'
setx -m HOME C:\Users\MyName
$ echo setx -m HOME C:\\Users\\MyName
setx -m HOME C:\Users\MyName

Or just call setx from a Windows shell like cmd or powershell. But as I said, if you need to call setx from a script every time you run it then you're doing it wrong. In that case you need to use a normal set:

set "HOME=%USERPROFILE%"
phuclv
  • 37,963
  • 15
  • 156
  • 475