0

I have a path I want to use as a home directory in WSL, but it's also path that has spaces in it.

I've tried escaping the spaces with slashes, and I've tried using single and double quotes with just spaces in the file, but it sets me at the root directory, instead of my home directory, it seems I cannot specify a path with spaces in it within /etc/passwd.

Is there some other way to make this work?

leeand00
  • 4,615
  • 1
    What happens when you just use a plain space? What errors occur, in what situations? – Jeff Schaller Sep 18 '19 at 13:13
  • @JeffSchaller That was it. Put it as the answer I'll accept it. – leeand00 Sep 18 '19 at 13:37
  • 1
    I assumed you had already tried it! I was curious what was breaking as a result... – Jeff Schaller Sep 18 '19 at 13:40
  • However...now my .bashrc isn't working, I have to source ~/.bashrc manually, even though I have it in my present ~. – leeand00 Sep 18 '19 at 13:41
  • I'd expect bash to expand ~ appropriately, though I haven't tested it. Do you have a file that's explicitly sourcing $HOME/.bashrc without quoting $HOME? – Jeff Schaller Sep 18 '19 at 13:42
  • 1
    I'll put an answer for now, but I'm curious what's really tripping up the situation. – Jeff Schaller Sep 18 '19 at 13:50
  • @JeffSchaller I'm unsure, are you talking about something like .bash_profile? but my $HOME variable doesn't appear to contain single or double quotes or escape characters. Maybe I need to ask another question... – leeand00 Sep 18 '19 at 13:53
  • 1
    What do you mean by "it never seems to work"? – Chris Davies Sep 18 '19 at 13:53
  • 1
    I meant that one possible failure scenario would be: source $HOME/.bashrc, when it should be source "$HOME"/.bashrc. Perhaps it's worth a separate question with the steps to reproduce it. – Jeff Schaller Sep 18 '19 at 13:54
  • I very strongly recommend against doing this. It will break a lot of stuff that assumes home directory names don't have spaces. Including, as has been mentioned, scripts that fail to properly double-quote "$HOME". Technically, having spaces in a homedir name is possible. Practically, it will cause hassles forever, for yourself and anyone else who has to deal with it.. – cas Sep 19 '19 at 03:45

1 Answers1

3

Simply use a space:

username:x:42:42:Jeff Schaller:/home/spaces here/username:/bin/bash
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255