Shell script runs when using the command: ./script, but not the command: script, where PATH=.:'usr/bin':etc

I'm running Zsh, with my current directory in my path, but the script doesn't run when used without ./

Read these statements executed in my terminal to understand the context (the » is my shell prompt character):

» ls
Makefile node_modules  package.json  README.md  src test  tst
» echo $PATH
.:[all_my_other_directories]
» cat test
echo "test";
nodeunit tst/
» ./test                                                                                                                                               
test
OK: 2 assertions (1ms)
» test
» which test
./test

Notice that on the which test points to the right spot, but test doesn't run it.

I know that putting my local directory in front of my path is a bad idea, but I've changed the path to having . at the end and it doesn't change anything.

I would greatly appreciate any help!

The keyword test is reserved because it is actually a shell builtin. To compound the confusion, there is also a shell command also called test.

Use a different name instead =)

@sampson-chen is completely right. One addition: to check what exactly you will run use

type test

, it will give you

test is a shell builtin

and thus resolve the problem. Don’t use which, it always looks for a command. type is equivalent to whence -v thus you can use the former instead.