make a bash script accesible from anywhere in the system
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
make a bash script accesible from anywhere in the system
I have written a number of scripts, basically to recursively manipulate files and images in directories. I have to copy the scripts into the pwd to run them, which becomes burdensome.
How can I export the path to a bash script so wherever I am in the system I can do
$ sh myscript.sh
without myscript.sh being in the precise pwd of the moment?
Thanks!
Thnx, but I bumped into this problem.
One script is a csh one.
When I place it at /usr/local/bin and do
$ csh myscript.sh
myscript: No such file or directory
$ sh myscript.sh
returns syntax errors (my default shell is a bash one).
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Can you explain better:
- how do you fail to export your path to subshells ?
- why do you need to launch your script with "sh script" instead of "script" ?
I would go with perfect-circle's advice of putting the she-bang (#!/bin/...) line at the beginning of each script. That way you don't have to figure out what shell goes with which script. It is both self documenting and self running.
To execute a script from anywhere on your system it needs to be in your $PATH environment variable. It is common to place scripts that anyone can execute in /usr/local/bin. If you are a user and want to execute scripts that you wrote, place them in your own bin and make sure this gets into your $PATH. For example if your user name is scooby then put your scripts in /home/scooby/bin.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.