Search code examples
terminalshzshoh-my-zsh

How can I use a second directory to stor shell scripts for a zsh shell?


I want to create a directory (for instance ~/scripts) in which every file I store, could be executed globally:

~/scripts/xy

echo hello world

Just as if it was located under /user/loca/bin.

I have tried add this line to .zshrc:

export PATH="~/scripts:$PATH"

But still get:

zsh: command not found: xy

So I would like to get some help.

Thanks

EDIT: My .zshrc file looks like this and it worked:

export ZSH="$HOME/.oh-my-zsh"

ZSH_THEME="robbyrussell"

plugins=(git)

source $ZSH/oh-my-zsh.sh

export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin:$PATH"
export PATH=$HOME/scripts:$PATH

Solution

  • The double quotes prevent ~ from being expanded. Either put at least the ~/ outside the quotes, or express your home directory using $HOME.

    BTW a perhaps more readable version is to use path instead of PATH:

    path+=~/.scripts
    

    Note that this appends your scripts directory at the end of the path instead at the beginning. This is probably the better choice anyway.