HOWTO Set the HOME variable for cmd exe

  • strict warning: Non-static method Text_Wiki::singleton() should not be called statically in /var/www/drupal/6.x/sites/ on line 475.
  • strict warning: Non-static method Text_Wiki::factory() should not be called statically in /usr/share/php/Text/Wiki.php on line 448.
  • strict warning: Non-static method Text_Wiki::isError() should not be called statically in /usr/share/php/Text/Wiki.php on line 449.
  • strict warning: Declaration of Text_Wiki_Parse_Emphasis::process() should be compatible with Text_Wiki_Parse::process(&$matches) in /usr/share/php/Text/Wiki/Parse/Mediawiki/Emphasis.php on line 0.

Set the HOME variable

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 the HOME variable in the cmd.exe 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. Globally setting this to a different directory than %USERPROFILE% 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. On the other hand, globally setting it to %USERPROFILE% may lead to errors if the %USERPROFILE% variable contains spaces, e.g. "C:\Users\Firstname Lastname".

Thus, the recommended way to set the HOME variable for the cmd.exe environment 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. Once this file is created, open the Windows Registry Editor regedit.exe and add its file path to the "AutoRun" key in either

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]

for the current user or

[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]

for system-wide availability. The exported Windows Registry key will look like this:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]

An example for the %USERPROFILE%\\cmdrc.bat batch file is shown below:

@echo off

set MSYSDIR=%MINGWDIR%\msys\1.0


rem Useful doskey macros
%SYSTEMROOT%\System32\doskey.exe ^D=exit
%SYSTEMROOT%\System32\doskey.exe ll=ls -l $*
%SYSTEMROOT%\System32\doskey.exe vi=vim -N $*
%SYSTEMROOT%\System32\doskey.exe which=sh -c "which $*"
  • The additional doskey macros shown at the end of the example are optional. They 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 created via [Ctrl]+[d], not [^], [D].

Site Status

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