尝试设置 bash 命令
我试图在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.我找到了自己的答案...符号链接是由一个自动文件创建的,该文件正在胡言乱语我的密码。我还使用了 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.
我将命令安装在
$HOME/bin
中,而不是/usr/local/bin
中,但这并不重要。正如评论中所暗示的,一个问题是符号链接是否设置正确。which command
/usr/local/bin
中的链接是否指向正确的文件(并且具有执行权限等) :ls -l /usr/local/bin/command
ls -lL /usr/local/bin/command
文件 /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.which command
/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
file /usr/local/bin/command
/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.