0

I have a file .aliases that I point to in my .zshrc file

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ -f $DIR"/.aliases" ]; then
    . $DIR"/.aliases"
fi

This code is the same in my .bashrc file (in the process of switching over to zsh). The aliases work fine when I open a new terminal - however when I change directory and open tmux, the aliases break. At first I thought this had something to do with whether the directory is the correct one - however, when I switch to bash, it works! So I am very confused as to what is causing this issue.

Andrew
  • 6,295
  • 11
  • 56
  • 95
  • 2
    `BASH_SOURCE` is a `bash`-specific variable; it's not defined in `zsh`. – chepner Jun 17 '15 at 23:06
  • Why do you think it works when I start the shell? Wouldn't it fail then if that was an issue, not just in tmux/different directory? I guess unless it assigns it an empty string if it fails? – Andrew Jun 17 '15 at 23:07
  • If the snippet you show is indeed in your `.zshrc` file, then `${BASH_SOURCE[0]}` will expand to the empty string, because `BASH_SOURCE` will not have a value when `.zshrc` is sourced by `zsh`. – chepner Jun 17 '15 at 23:08
  • Ok, I found this old answer to fix it, seems to work now. http://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh. Want to post your comment as an answer so I can accept it? – Andrew Jun 17 '15 at 23:12

1 Answers1

1

BASH_SOURCE cannot be used in .zshrc, because it is a bash-specific variable that isn't defined in zsh. You'll have to replace it with its zsh equivalent, found here.

Community
  • 1
  • 1
chepner
  • 497,756
  • 71
  • 530
  • 681