你可以使用第二个目录来存储 zsh shell 脚本。

huangapple go评论47阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月5日 18:32:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405555.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定