Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
/bin/zsh

$ echo $PATH
/home/user1/bin:/home/user1/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/usr/X11R6/bin:/usr/X11/bin:/usr/kerberos/bin

$ which ssh
~/bin/ssh

$ builtin which -a ssh
/home/user1/bin/ssh
/usr/bin/ssh

$ alias
l.='ls -d .* --color=tty'
ll='ls -lh'
ls='ls --color=auto'
run-help=man
vi=vim
which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
which-command=whence
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.