英文:
How can I use a second directory to stor shell scripts for a zsh shell?
问题
以下是翻译好的部分:
我想要创建一个目录(例如 ~/scripts
),在这个目录中存储的每个文件都可以在全局范围内执行:
~/scripts/xy
echo hello world
就好像它位于 /usr/local/bin
下一样。
我尝试将以下行添加到 .zshrc 中:
export PATH="~/scripts:$PATH"
但仍然收到以下错误:
zsh: command not found: xy
所以我想要得到一些帮助。
谢谢
编辑:我的 .zshrc 文件看起来像这样,它可以正常工作:
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
英文:
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
答案1
得分: 0
双引号阻止了~
的扩展。要么将至少~/
放在引号外,要么使用$HOME
来表示您的主目录。
顺便说一下,更可读的版本是使用path
而不是PATH:
path+=~/.scripts
请注意,这将在路径末尾附加您的脚本目录,而不是在开头。这可能是更好的选择。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论