简体   繁体   English

将script.sh移至bin

[英]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.

相关问题 “源脚本.sh”和“./script.sh”有什么区别? - What is the difference between “source script.sh” and “./script.sh”? -bash:script.sh:/ usr / bin / ksh:错误的解释器:权限被拒绝 - -bash: script.sh: /usr/bin/ksh: bad interpreter: Permission denied 检查进程是否运行,如果不执行script.sh - Check if process runs if not execute script.sh 在执行 script.sh 之前,检查 script.sh 是否正在运行,如果它正在运行 kill 并继续 - before executing script.sh, Check script.sh running or not, if its running kill and continue ./script.sh和bash script.sh之间的区别是什么 - what's the difference between ./script.sh and bash script.sh 我下载了stip-2.0 linux,并尝试执行“ script.sh”,但发生此错误。/bin/stipdet:1:./bin/stipdet:syntax错误:“(”意外 - I downloaded stip-2.0 linux, and i try to execute “script.sh” , but this error occurs ./bin/stipdet:1: ./bin/stipdet:syntax error:“(” unexpected 如果我们运行 >./script.sh 会对任何脚本产生什么影响 - What will be the impact on any Script if we run >./script.sh bash:./script.sh:参数列表太长 - bash: ./script.sh: Argument list too long Linux - grep -e在从命令调用script.sh时起作用,但在从crontab调用script.sh时失败 - Linux - grep -e works when invoke the script.sh from command but fails when the script.sh is called from crontab 当执行'sh script.sh /path/foo.py'时,自动补全功能不起作用 - Autocompletion doesn't work when exectute 'sh script.sh /path/foo.py'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM