views:

202

answers:

2

I'm having a rather strange problem with zsh. When I start up my shell, everything - functions, environment vars, aliases, etc. - all work fine. I've created the following function and sourced it in zsh:

clean()
{
    path=/tmp    
    for i in ${path}/*; do
      echo $i
    done
}

Running clean in the terminal works as expected, in that it prints out all the files in /tmp/. Afterward, however, trying any command - for example, ls - produces this:

zsh: command not found: ls

I have several other functions that work just fine, which leads me to believe that somehow, that loop is causing the problem. At any rate, this is very frustrating and I would sincerely appreciate the community's eyes. Thanks!

+2  A: 

The problem is assigning the path variable - since zsh has that variable reserved (in addition to PATH), overwriting it removes the ability for the shell to find any command.

The correct answer, of course, is to use a variable other than $path:

local_path=/tmp    
for i in ${local_path}/*; do
  echo $i
done
ABach
accept your answer. I suspect you were overwriting the PATH variable. which is very important. use a different one that's not already in the env. CLEAN_PATH shouldn't have this affect for example.
xenoterracide
Oh my... how obvious is that. Thank you. :)
ABach
Also - I can only accept my own answer in two days...
ABach
Try running your original function after `set -x` and see if the trace tells you anything.
Dennis Williamson
apparently here's the documentation on that http://zsh.sourceforge.net/Doc/Release/Parameters.html#SEC98 PATH and path are different but zsh has both and that means you shouldn't mess with them.
xenoterracide
"accept your answer" hello?
Lo'oris
Lo'oris - I cannot accept my answer until 22 hours from now - sorry.
ABach
lol, you should accept **my** answer, since I said the same thing a few minutes before...
Lo'oris
A: 

I guess it overwrites the variable path, which is the one used to find commands. That's why it doesn't find commands anymore.

Lo'oris