In Terminal, when the the “cd” command is called, libwww-perl's “head” command is also executed Currently, in Terminal, when I execute a cd command, it also executes LWP's head command.

A copy of the Terminal output follows:

laptop:bin user$ cd ~
Unknown option: n
Usage: head [-options] &lt;url&gt;...
    -m &lt;method&gt;   use method for the request (default is 'HEAD')
    -f            make request even if head believes method is illegal
    -b &lt;base&gt;     Use the specified URL as base
    -t &lt;timeout&gt;  Set timeout value
    -i &lt;time&gt;     Set the If-Modified-Since header on the request
    -c &lt;conttype&gt; use this content-type for POST, PUT, CHECKIN
    -a            Use text mode for content I/O
    -p &lt;proxyurl&gt; use this as a proxy
    -P            don't load proxy settings from environment
    -H &lt;header&gt;   send this HTTP header (you can specify several)

    -u            Display method and URL before any response
    -U            Display request headers (implies -u)
    -s            Display response status code
    -S            Display response status chain
    -e            Display response headers
    -d            Do not display content
    -o &lt;format&gt;   Process HTML content in various ways

    -v            Show program version
    -h            Print this message

    -x            Extra debugging output
laptop:bin user$


I've reviewed the ~/.bash_profile and ~/.bashrc but there are only three export statements and no alias or something like that. It's as follows:

[[ -s "/Users/user/.rvm/scripts/rvm" ]] &amp;&amp; source "/Users/user/.rvm/scripts/rvm"  # This loads RVM into a shell session.
### Added by the Heroku Toolbelt
export PATH="/Applications/XAMPP/xamppfiles/bin:/usr/local/heroku/bin:$PATH"
export PATH=/Users/user/bin/Sencha/Cmd/3.1.2.342:$PATH
export SENCHA_CMD_3_0_0="/Users/user/bin/Sencha/Cmd/3.1.2.342"
export PATH=$PATH:/Applications/acquia-drupal/drush


From reading, it seems that installing LWP might have overwritten the /usr/bin/head command, but I've checked and it's the OSX one. However, when I call head from Terminal, it invokes the LWP head command instead.

Per patrix's request, here are the contents of ~/.rvm/scripts/rvm: http://pastebin.com/7rZVQAcy

I'll keep out trying things, and I'll update the question with new information if relevant.

Additional information:

laptop:dir user$ alias cd
-bash: alias: cd: not found
laptop:dir user$ which cd
/usr/bin/cd
laptop:dir user$ which head
/Applications/XAMPP/xamppfiles/bin/head


The output of echo "$PS1"; echo "$PROMPT_COMMAND" is:

\h:\W \u\$ 
update_terminal_cwd;


The output of type -a update_terminal_cwd is:

update_terminal_cwd is a function
update_terminal_cwd () 
{ 
    local SEARCH=' ';
    local REPLACE='%20';
    local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}";
    printf '\e]7;%s\a' "$PWD_URL"
}


The output of type -a cd is:

cd is a function
cd () 
{ 
    if builtin cd "$@"; then
        __rvm_do_with_env_before;
        __rvm_project_rvmrc;
        __rvm_after_cd;
        __rvm_do_with_env_after;
        return 0;
    else
        return $?;
    fi
}
cd is a shell builtin
cd is /usr/bin/cd
I am going to assume you are using bash.

So in that case when you just type cd it should be running the bash built-in. This is what has the problem.

To confirm this try using the external version - at the command prompt type /usr/bin/cd and you should go to your home directory with no problems.

Now let's check what the other cd might be up to.

type -a cd should give us

cd is a shell builtin
cd is /usr/bin/cd


which head should give us /usr/bin/head

alias might give us a long list but nothing pointing towards an alias for cd

The CD environment variables should have sane entries:

CDARGS_NODUPS=1
CDARGS_SORT=0
CDPATH='.:~:~/bin:~/dev:/usr:/'


The same with:

PROMPT_COMMAND='history -a; history -n; printf "\e]1;${PWD}\a"'
PS1='\[\033[34m\]\h:\W \u$\[\033[0m\] '
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor


If all that is OK then my money would be on cd being redefined by a builtin function that has gone pear shaped. At the command line set | less will allow you to page through a dump of all your shell variables, aliases and functions. If you type / you can search through the file for cd (notice the space) and see if that is happening.

Once you have discovered that "someone" - in your case rvm - is defining a shell function called cd then you can either uninstall the culprit or find where it does the nasty work and change the name of the function to something like 'rcd' instead of 'cd'. As the shell function is listed first in the output of type the builtin cd is ignored except where it is getting called by the function (that's what the builtin cd in the function definition is doing - calling the builtin version).

I'd almost guarantee that the function is defined in /Users/user/.rvm/scripts/rvm.

I'd start by uninstalling rvm and then reinstall to see if that fixes it. Are you installing it using MacPorts or Homebrew?