Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My zsh is doing something odd, it is running an executable that is not the first executable on my path. I have a wrapper script for ssh but the wrapper is not being invoked while the real ssh binary is being invoked instead.

Some diagnostics:

$ echo $SHELL

$ echo $PATH

$ which ssh

$ builtin which -a ssh

$ alias
l.='ls -d .* --color=tty'
ll='ls -lh'
ls='ls --color=auto'
which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
zcp='noglob zmv -W -C'
zln='noglob zmv -W -L'
zmv='noglob zmv -W -M'

I tried running 'ssh' in bash and my wrapper script was invoked, so it seems like it's a problem with zsh.

Please let me now if any other diagnostic information is needed.

I would really like to know why is it that the $PATH variable is being ignored when I try to invoke ssh.

Update 1

Added the output from 'builtin which -a ssh'

share|improve this question
That alias for which does irritate me. Can you please post the output of builtin which -a ssh? And, as user232011 already pointed out rehash (= hash -r) is always worth a try when it seems that programs in the PATH are not correctly picked up. – mpy Jun 18 '13 at 14:25
up vote 4 down vote accepted

From the info page, zsh uses a hash table to store the paths to executables. I am guessing that you did things in this order.

  1. Started zsh session
  2. Ran standard ssh, this would store the path in the hash table.
  3. Created wrapper script.
  4. Ran ssh, this picks up the wrong (out of date) path from the hash table.
  5. Ran which ssh, this just checks the PATH, not the zsh hash table.

The info page for zsh suggests that hash -r will clear the hash table, after which the hash table will be rebuilt which should pick up your wrapper script.

When you started bash it didn't share the zsh internal hash of paths, so it just starts looking in the PATH to find things.

share|improve this answer
FYI: bash has this hash as well, also use hash -r to clear it. – Rich Homolka Jun 18 '13 at 14:26
This fixed the problem completely. Thanks. – Alex Q Jun 18 '13 at 17:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .