[英]Move script.sh to bin
I'm new to shell programming and I'm trying to create a simple script that gives me some infos on the status of the machine (ie date, time, users logged in etc) on Scientific Linux 6 (I know it's old, but the department of my university runs on it so there's no escaping) 我是Shell编程的新手,我正在尝试创建一个简单的脚本,该脚本向我提供有关Scientific Linux 6上计算机状态(即日期,时间,用户登录等)的一些信息(我知道它很旧,但是我大学的系在上面运行,所以没有逃脱的机会)
Basically I've created my script "sysinfo.sh" 基本上我已经创建了脚本“ sysinfo.sh”
#!/bin/sh
....
exit 0
as root user I want to move it so that I can be able to execute it anywhere and I thought the right way to do it was 作为root用户,我想移动它,以便可以在任何地方执行它,我认为正确的方法是
sudo mv sysinfo.sh usr/local/bin
but I get the error message 但我收到错误消息
mv: cannot move `sysinfo.sh' to `usr/local/bin': No such file or directory
then I looked for the PATH and it gives me 然后我寻找路径,它给了我
$ echo $PATH
/u/geo2/sw//System/tools/bin:/usr/bin:/bin
What is the right place to move my script? 移动脚本的正确位置是什么?
Best practice for these kind of manipulation or learning is to have scripts in your $HOME/bin directory. 这些操作或学习的最佳实践是在$ HOME / bin目录中包含脚本。
mkdir $HOME/bin
export PATH=$PATH:$HOME/bin
mv sysinfo.sh $HOME/bin
chmod +x $HOME/bin/sysinfo.sh
If you anyway want to move it to /usr/local/bin, why not do that with: 如果您仍然要将其移动到/ usr / local / bin,为什么不这样做:
sudo mv sysinfo.sh /usr/local/bin
chmod +x /usr/local/bin/sysinfo.sh
chmod command will make the script executable. chmod命令将使脚本可执行。
from chmod man: 来自chmod man:
x -- The execute/search bits. x-执行/搜索位。
The command that you posted indicates that you were trying to use the absolute path for copying, but you missed a leading slash -- the directory should be /usr
instead of usr
. 您发布的命令表明您正在尝试使用绝对路径进行复制,但是您错过了一个斜杠-目录应为/usr
而不是usr
。
Try 尝试
sudo mv sysinfo.sh /usr/local/bin
Note that unless an absolute path is specified, the shell looks for the path relative to the current working directory. 请注意,除非指定了绝对路径,否则外壳程序将查找相对于当前工作目录的路径。 In this case, the shell was looking for the subdirectory usr
under the current directory which was not found; 在这种情况下,外壳程序会在找不到当前目录下的子目录usr
下进行查找; hence the error message. 因此错误消息。
Thank you very much! 非常感谢你! In the end, I didn't realize that the directory /usr/local/bin wasn't in the PATH So i just needed to 最后,我没有意识到目录/ usr / local / bin不在PATH中,所以我只需要
export PATH=$PATH:/usr/local/bin
sudo mv sysinfo.sh /usr/local/bin
:D :D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.