Home > Back-end >  Z shell does not find script in working directory
Z shell does not find script in working directory

Time:01-08

I don't understand the following behavior:

enter image description here

This is a Z shell terminal on macOS 12.1.

The working directory is "Config & Scripts".
When I just type .mouseBatteryCheck.sh I get command not found.
When I add the full path, it's fine.

Doesn't Z shell always look in the working directory?
Does it only look in the directories specified in PATH?

CodePudding user response:

Turn my comment into an answer:

Does it only look in the directories specified in PATH?

Yes. And you should not have . in PATH for security reasons. Simply run the script with ./.mouseBatteryCheck.sh (assuming it has the x bit set with chmod x .mouseBatteryCheck.sh).

CodePudding user response:

No, fortunately the shell does not look by default in the working directory. You have to run it explicitly as

./.mouseBatteryCheck.sh

or as

zsh .mouseBatteryCehck.sh

If you use the former way, you have to provide a #! line in the script to ensure that it will be executed by zsh.

  •  Tags:  
  • Related