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开发者_StackOverflow中文版 exist in this location. When I edit the $PATH setting, these fail.
Suggestions?
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.
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.
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.
精彩评论