zsh无法在〜/bin中查找或执行自定义用户脚本,尽管它们是可执行文件并且在$ PATH环境变量中 [英] zsh can neither find nor execute custom user scripts in ~/bin although they are executable and in the $PATH environment variable

查看:274
本文介绍了zsh无法在〜/bin中查找或执行自定义用户脚本,尽管它们是可执行文件并且在$ PATH环境变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我最近已从macOS Mojave 10.14.6升级到macOS Catalina 10.5.5.

I have recently upgraded from macOS Mojave 10.14.6 to macOS Catalina 10.5.5.

现在zsh是默认的shell,我将.bashrc迁移到了.zshrc:

Now that zsh is the default shell, I migrated my .bashrc to .zshrc:

  • 别名工作正常.
  • 但是由于某些无法解释的原因,我在~/bin/my/~/bin/dev/中的自定义用户脚本是
    • 未通过自动补全完成
    • 完全键入时无法被唤起,然后我得到zsh: command not found: myScript.sh
    • Aliases work fine.
    • But for some unexplainable reason, my custom user scripts in ~/bin/my/ and ~/bin/dev/ are
      • not completed by autocompletion
      • cannot be evoked when typed entirely, I then get zsh: command not found: myScript.sh

      调查和故障排除:

      • 将shell改回bash时,一切仍然有效,因此可以排除OS更新引起的数据丢失/损坏,这一定是配置问题.
      • 我所有的脚本文件都具有可执行标志.
      • 它们所在的目录位于$ PATH环境变量中.
        • 证明:echo $PATH给出/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/sbin:~/bin/bin:~/bin/my:~/bin/dev:
        • When changing the shell back to bash, everything still works, so data-loss/corruption from the OS update can be ruled out, it must be a configuration issue.
        • All my script files have the executable flags.
        • The directories they reside in are in the $PATH environment variable.
          • Proof: echo $PATH gives /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/sbin:~/bin/bin:~/bin/my:~/bin/dev:

          实验:

          • 我尝试使用/不使用export关键字来设置/附加$ PATH变量. ->没什么.
          • 我尝试了各种可能的配置文件:.zprofile .zshrc->没什么区别.
          • 我将bash和zsh配置文件硬链接起来,并包括:alias test123="echo test123"
            • 此别名在bash和zsh中有效.因此,在加载配置文件的链中这不是问题.
            • I tried setting/appending the $PATH variable with and without the export keyword. --> Makes no difference.
            • I tried the various possible config files: .zprofile .zshrc --> Makes no difference.
            • I hardlinked the bash and the zsh config file and included: alias test123="echo test123"
              • This alias works in bash and zsh. So it cannot be a problem in the chain of loading config files.

              推荐答案

              我在 William Pursell的答案中找到了解决方案使用zsh PATH的怪异行为:

              I found the solution in William Pursell's answer concerning Weird behaviour with zsh PATH:

              尝试使用$ HOME代替〜.在许多情况下,shell不会扩展〜当您期望它们扩展时,通常最好使用$ HOME. 〜实际上仅是用于交互式使用的捷径.

              Try using $HOME instead of ~. In many situations, shells do not expand ~ when you expect them to and it is usually better to use $HOME. ~ is really only intended to be a short cut for interactive use.

              从那时起,zsh按预期工作,并在我用$PATH中的$HOME变量替换了所有~代字号占位符之后,考虑了~/bin/*中的所有客户用户脚本. —错误的角色可以带来多大的改变!

              From then on zsh worked as expected and considered all my customer user scripts in ~/bin/* after I have replaced all my ~ tilde placeholders with $HOME variables in my $PATH. — What a great difference a wrong character can make!

              这篇关于zsh无法在〜/bin中查找或执行自定义用户脚本,尽管它们是可执行文件并且在$ PATH环境变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆