Shell – this HOME command

shell-builtinzsh

I'm able to run a command named "HOME" which appears to be equivalent to cd && echo "~".
But I can't figure out where it's defined:

$ pwd
/tmp
$ which HOME
HOME not found
$ type HOME
HOME not found
$ man HOME
No manual entry for HOME
$ HOME
~
$ pwd
/Users/tba

Is this a shell builtin?
It seems more like a failed attempt to print the fully-qualified path of my home directory.

I'm running ZSH (with Oh-My-Zsh) on OS X Yosemite.

Best Answer

oh-my-zsh enable two things, which cause this behavior:

  • AUTO_CD: If command can not execute, and command is a directory name, perform cd to that directory
  • CDABLE_VARS: If the argument to a cd command (or an implied cd with the AUTO_CD option set) is not a directory, and does not begin with a slash, try to expand the expression as if it were preceded by a ~

In your case, when typing HOME, AUTO_CD made zsh performed cd HOME, CDABLE_VARS made zsh performed cd ~HOME, ~HOME was expanded to your home directory.

You can call zsh with --xtrace option to see what happened:

$ zsh --xtrace
$ HOME
...
+zsh:1> cd /home/cuonglm
~
....
Related Question