[英]OS X Shell Script executable not working
I have a shell script that I'm trying to make executable. 我有一个要执行的Shell脚本。
Here's the script: (it doesn't do anything useful yet. just trying to get it to run properly) 这是脚本:(它没有做任何有用的事情。只是试图使其正常运行)
#!/bin/sh
function rip_it_good(){
echo "function called"
}
rip_it_good
First I made it executable: 首先,我将其设为可执行文件:
$ chmod +x ripitgood.sh
So far, so good. 到现在为止还挺好。 If I run it from terminal in the local directory
如果我从本地目录中的终端运行它
$ ./ripitgood.sh
it runs just fine and I get the proper output of "function called". 它运行得很好,我得到了“调用的函数”的正确输出。
Next I linked to it from /usr/local/bin 接下来,我从/ usr / local / bin链接到它
$ sudo ln -s ripitgood.sh /usr/local/bin/ripitgood
But if I try to run it using the newly created link: 但是,如果我尝试使用新创建的链接运行它:
$ ripitgood
I get an error 我得到一个错误
"-bash: ripitgood: command not found" “ -bash:ripitgood:找不到命令”
I checked, and yes /usr/local/bin is in my PATH 我检查了, 是的 / usr / local / bin在我的PATH中
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin
And I tried to run it directly 我试图直接运行
$ /usr/local/bin/ripitgood
-bash: /usr/local/bin/ripitgood: No such file or directory
So, I opened up finder and checked, and yes, the link "ripitgood" exist in the /usr/local/bin directory 因此,我打开了finder并进行了检查,是的,/ usr / local / bin目录中存在链接“ ripitgood”
I can still run it from the directory where it resides: 我仍然可以从它所在的目录运行它:
./ripitgood.sh
function called
What am I missing? 我想念什么?
The problem is in how you create the symlink: 问题在于如何创建符号链接:
sudo ln -s ripitgood.sh /usr/local/bin/ripitgood
The symlink will literally be ripitgood.sh
, but there is no ripitgood.sh
in /usr/local/bin
. 该符号链接实际上是
ripitgood.sh
,但/usr/local/bin
没有ripitgood.sh
。 Try creating the symlink like this: 尝试像这样创建符号链接:
sudo ln -s $(pwd)/ripitgood.sh /usr/local/bin/ripitgood
That will use the full, absolute path to ripitgood.sh
in the symlink. 这将使用符号链接中
ripitgood.sh
的完整绝对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.