Revision of HOWTO Set the HOME variable for cmd exe from 2011, May 27 - 09:32

Printer-friendly version

The HOME variable is one of the essential variables required by *NIX systems. It is already set in an MSYS environment, but not in a cmd.exe environment. Some applications, e.g. vim.exe, may behave erroneously or even crash if this variable is missing. In order to use these application from cmd.exe, it is thus required to set this variable in this environment as well.

One possible solution is to add HOME to the list of global variables in the System section of the Windows Control Center. This is not recommended, however, because it may change the behaviour of already installed applications, e.g. VirtualBox, and mislead them to look in this location for their configuration data.

The recommended way is to create some kind of rc-script (like ~/.bashrc for bash) for cmd.exe, i.e. a batch file that gets started whenever cmd.exe is invoked. Open the Windows Registry Editor regedit.exe and add its file path to the "AutoRun" key in either (only for the current user)

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]

or

[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]

for system-wide availability.

An example for such a batch file is shown below:

@echo off
rem Windows Registry Editor Version 5.00
rem 
rem [HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
rem "AutoRun"="C:\\Users\\Admin\\cmdrc.bat"

set MINGWDIR=C:\MinGW
set MSYSDIR=%MINGWDIR%\msys\1.0

set HOME=%MSYSDIR%\home\%USERNAME%
set PATH=%PATH%;%MINGWDIR%\bin;%MSYSDIR%\bin

doskey ^D=exit
doskey ll=ls -l $*
doskey vi=vim -u %MSYSDIR%\share\vim\vim73\vimrc_example.vim $*
doskey which=sh -c "which $*"
The additional doskey macros shown at the end of the example may come handy for those who are used to certain shortcuts from their *NIX enviroment, but may cause erroneous behaviour for applications which use cmd.exe internally, e.g. Ansys Fluent.
The ^D character in the exit macro is not created via [Ctrl]+[d], not [^], [D].

Site Status

Site maintenance completed May 25th, 2012 at 12:38 UTC