尝试设置 bash 命令

发布于 2024-09-14 23:36:00 字数 203 浏览 1 评论 0原文

我试图在 Mac 上的终端中设置 bash 命令。

当我直接执行脚本时,脚本可以正确运行。

我在 /usr/local/bin/ 中设置了指向脚本当前位置的符号链接。当我尝试从符号链接运行它时,它不起作用。我不认为问题出在 $PATH 上,因为 pip、git、ipython 都存在于这个位置。当我编辑 $PATH 设置时,这些失败。

建议?

I was trying to set up a bash command in Terminal on a Mac.

The scripts run correctly when I execute them directly.

I set up symlinks in /usr/local/bin/ to the current location of the scripts. When I try to run it off the symlink, it doesn't work. I don't believe the issue is the $PATH, because pip, git, ipython all exist in this location. When I edit the $PATH setting, these fail.

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

§对你不离不弃 2024-09-21 23:36:00

ls -l /usr/local/bin/foo 并查看符号链接实际指向的位置。打赌它坏了。

如果没有,请尝试运行 /usr/local/bin/foo。如果有效,那么无论您在OP中说什么,都是您的路径错误。

唯一会导致此行为的另一件事是脚本是否正在读取 $0 (执行时它自己的名称)。使用符号链接,它将具有不同的值。

ls -l /usr/local/bin/foo and see where your symlink is actually pointing. Betcha it's broken.

If not, try running /usr/local/bin/foo. If that works, it was your PATH that's wrong, despite what you said in the OP.

The only other thing that would cause this behavior is if the script is reading $0 (its own name as executed). With a symlink, that will have a different value.

方觉久 2024-09-21 23:36:00

我找到了自己的答案...符号链接是由一个自动文件创建的,该文件正在胡言乱语我的密码。我还使用了 virtualenv,所以为了让它工作,我必须激活 virtualenv 并位于包含创建符号链接的脚本的文件夹中。

I found my own answer... The symlinks were created by an automated file which was gabbing my pwd. I was also using virtualenv, so to get it to work, I had to activate the virtualenv and be inside the folder that had the script that created the symlinks.

深白境迁sunset 2024-09-21 23:36:00

我将命令安装在 $HOME/bin 中,而不是 /usr/local/bin 中,但这并不重要。正如评论中所暗示的,一个问题是符号链接是否设置正确。

  • 检查 shell 认为您应该执行哪个命令: which command
  • 检查 /usr/local/bin 中的链接是否指向正确的文件(并且具有执行权限等) :
    • ls -l /usr/local/bin/command
    • ls -lL /usr/local/bin/command
  • 检查shebang中的解释器路径是否正确:
    • 文件 /usr/local/bin/command
  • 检查 /usr/local/bin 是否确实在您的 PATH 上:echo $PATH

如果这些都没有显示出问题,请向我们显示上述命令的结果。

I install my commands in $HOME/bin instead of /usr/local/bin, but it does not matter much. As hinted in the comments, one question is whether the symlinks are set correctly.

  • Check which command the shell thinks you should execute: which command
  • Check that the link in /usr/local/bin points to the correct file (and has execute permission, etc):
    • ls -l /usr/local/bin/command
    • ls -lL /usr/local/bin/command
  • Check that the interpreter path in the shebang is correct:
    • file /usr/local/bin/command
  • Check that /usr/local/bin is actually on your PATH: echo $PATH

If none of that shows up a problem, show us the results of the commands above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文