简体   繁体   中英

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)

Basically I've created my script "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

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.

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:

sudo mv sysinfo.sh /usr/local/bin
chmod +x /usr/local/bin/sysinfo.sh

chmod command will make the script executable.

from chmod man:

x -- The execute/search bits.

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 .

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; 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

export PATH=$PATH:/usr/local/bin
sudo mv sysinfo.sh /usr/local/bin

:D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM