In UNIX, I read that moving a shell script to /usr/local/bin will allow you to execute the script from any location by simply typing “[scriptname].sh” and pressing enter.
I have moved a script with both normal user and root permissions but I can’t run it.
The script:
#! bin/bash
echo "The current date and time is:"
date
echo "The total system uptime is"
uptime
echo "The users currently logged in are:"
who
echo "The current user is:"
who -m
exit 0
This is what happens when I try to move and then run the script:
[myusername@VDDK13C-6DDE885 ~]$ sudo mv sysinfo.sh /usr/local/bin
[myusername@VDDK13C-6DDE885 ~]$ sysinfo.sh
bash: sysinfo.sh: command not found
If you want to run the script from everywhere you need to add it to your
PATH. Usually/usr/local/binis in the path of every user so this way it should work.So check if in your system
/usr/local/binis in yourPATHdoing, on your terminal:You should see a lot of paths listed (like
/bin,/sbinetc…). If its not listed you can add it. A even better solution is to keep all your scripts inside a directory, for example in yourhomeand add it to your path.To add a directory in your path you can modify your
shellinit scripts and add the new directories, for example if you’re usin theBASHshell you can edi your.bashrcand add the line:This will append the new directories to your existing
PATH.