0

I'm using zsh 5.0.2 (x86_64-apple-darwin12.3.0) on the latest MacOSX. If it makes any difference, I have also enabled oh-my-zsh.

The shell seems to be missing the .zshrc file when I want to source it.

The result of the execution of the following commands should expose my problem clearly. (~ » is my prompt).

The file exists

~ » ls -l .zshrc
-rw-r--r--  1 user  staff  1882 May 16 10:43 .zshrc
~ » [[ -r .zshrc ]] && echo "Exists"
Exists

The file isn't read by "."

~ » . .zshrc
.: no such file or directory: .zshrc

I don't know what causes this behavior, especially that this works

~ » . "$(pwd)"/.zshrc
Success!

My question is:

Why won't . .zshrc work?

3

The . command searches for the file in your $path, it does not by default search in the current directory. That is why it works when you give the absolute path ("$(pwd)"/.zshrc).

From the zsh manual about the . command:

. file [ arg ... ]

Read commands from file and execute them in the current shell environment.

If file does not contain a slash, or if PATH_DIRS is set, the shell looks in the components of $path to find the directory containing file. Files in the current directory are not read unless ‘.’ appears somewhere in $path.

...

Compare to the source command:

source file [ arg ... ]

Same as ‘.’, except that the current directory is always searched and is always searched first, before directories in $path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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