1

I just installed bash.exe on a machine running Windows 10, and it works great except I can't seem to get ~ to point to where I want it (as in cd ~). It automatically points to C:.

How can I change this to reference C:\Users\name where all my commonly used files are located?

I've tried setting $HOME to the address that I want (using export HOME='C:\Users\name'), but that didn't work. echo ~ still returns C:

Any thoughts?

Installation Notes -- I simply downloaded bash.exe and other bash-like commands from SourceForge and added the entire downloaded directory to my path.

code_cowboy
  • 596
  • 5
  • 18
  • In PowerShell, `~` is defined in the `PSProvider`: `Get-PSProvider -PSProvider FileSystem | % Home`. However under bash, I'm uncertain how that system interprets it. – Maximilian Burszley Mar 05 '19 at 19:50
  • In PowerShell, `~` takes me to the correct place (i.e. `C:\Users\name`), but that doesn't seem to translate to bash. – code_cowboy Mar 05 '19 at 20:16
  • I think we'll need more details about **how** you installed bash.exe. Is this [Windows Subsystem for Linux](https://learn.microsoft.com/en-gb/windows/wsl/install-win10) or something else? – glenn jackman Mar 05 '19 at 20:22
  • Just edited to include this...please advise if not informative enough. – code_cowboy Mar 05 '19 at 20:27
  • This story has been asked before. Please check the suggested solutions in this post: https://stackoverflow.com/a/46898841/2166900 – GoGoris Mar 06 '19 at 14:12

2 Answers2

0

Oh, that wont work in bash with your example, you need cut \ if you wanna add a folder this way:

export HOME='C:\\Users\\name'

But, try this if you are inside a linux environment since c: gets mounted in /mnt by default :

export HOME='/mnt/c/users/name'

You also can try this with your example if you just running it from powershell:

Create a .bashrc file:

 C:\Users\USERNAME\.bashrc 

Now add below string to this file:

HOME=$PATH:/c/users/name 
Dominique
  • 16,450
  • 15
  • 56
  • 112
wuseman
  • 1,259
  • 12
  • 20
  • 1
    Thanks. Neither of these worked though. – code_cowboy Mar 05 '19 at 20:12
  • Try this: HOME=/c/Users/$USERNAME – wuseman Mar 05 '19 at 20:22
  • 1
    Sorry, neither of these worked either. – code_cowboy Mar 05 '19 at 20:29
  • Okey what about: Set-Variable HOME "C:\Users\usernamehere" -Force echo $HOME cd ~ Tried on my machine: Set-Variable HOME "C:\Users\wuseman\testdir\" cd $HOME pwd C:\Users\wuseman\testdir\ – wuseman Mar 05 '19 at 20:38
  • 1
    That doesn't work for me in either Powershell or bash. In powershell it states that my home env is changed (i.e. `echo $HOME` returns the correctly changed dir), but `cd ~` still goes to the original location. I should note that in powershell `cd ~` changes directory to `C:\Users\username`, but in bash it changes directory to `C:` – code_cowboy Mar 05 '19 at 20:46
  • Okey, my last idea that must work otherwise something is wrong. Enter your home dir - 'cd $HOME' type 'Set-Location ~' when you entered the dir, does '~' point to your $HOME dir now? – wuseman Mar 05 '19 at 20:59
  • 1
    This also does not work. I have a feeling that bash somehow misinterprets where the home directory is. Please note that I am not running Windows Subsystem for Linux, but rather installed `bash.exe` from sourceforge and simply added it to my path (see Installation Notes in edits to original question). Bash also is not able to find my `.bashrc` file, so I have to explicitly provide that with the `-rcfile` flag and a path to my `.bashrc` file. I'm guessing it looks for that in `C:`. – code_cowboy Mar 05 '19 at 21:23
  • @wuseman You cannot set `$HOME` in PowerShell. It's an automatic (read-only) variable. – Maximilian Burszley Mar 05 '19 at 21:33
0

Surprisingly the HOME variable which rules the expansion of ~ in win-bash is not the bash variable of this name, but rather the Windows environment variable. So, we can change where ~ goes only if we set HOME before bash is started, e. g. in cmd with set HOME=….

Armali
  • 18,255
  • 14
  • 57
  • 171