Declaring script globally

General support questions
Post Reply
knzzz
Posts: 157
Joined: 2017/02/25 12:41:42

Declaring script globally

Post by knzzz » 2017/11/25 01:33:56

Hi All,

i want to run the script which exist in /tmp/test.sh , now i want to run the script globally i.e i should not give the absoulte path
when i tried export PATH="$PATH:/tmp/test.sh" ; export $PATH when i logout and logged in still am unable to run the test.sh globally

Regards
Kanna

vacosta
Posts: 2
Joined: 2014/09/23 18:36:10

Re: Declaring script globally

Post by vacosta » 2017/11/25 02:36:59

Hello, how are you?
I'm trying to understand what you need to do.

Do you want to get your script available for all system users like 'cp' or 'mv' command? If this si your case you can copy your script to /usr/local/bin or /usr/local/sbin, and just run test.sh

Do you want to execute your script at every user login? If this is your case you can use .bash_profile for every user that you need to run the script or edit your /etc/skel/.bash_profile to get it to every new user

Whoever
Posts: 1357
Joined: 2013/09/06 03:12:10

Re: Declaring script globally

Post by Whoever » 2017/11/25 06:52:02

knzzz wrote:Hi All,

i want to run the script which exist in /tmp/test.sh , now i want to run the script globally i.e i should not give the absoulte path
when i tried export PATH="$PATH:/tmp/test.sh" ; export $PATH when i logout and logged in still am unable to run the test.sh globally

Regards
Kanna
1. You should set the PATH to include only the directory that contains the script you want to run, not the script itself.
2. Including /tmp in your $PATH is a very bad idea from a security perspective.
3. /tmp is likely to be wiped at any time and almost certainly on reboot.
4. Changes to environment variables only affect that instance of the shell (and, if you export the variables, any sub-shells). You need to change one of the many files that can be used to set your environment. If by "globally" you mean all users, then put a new file in /etc/profile.d that sets the PATH variable. If you mean yourself, but in any shell, put a line in ~/.bashrc that sets the PATH variable.

PATH is already exported, so you only need to set its value:

Code: Select all

PATH="$PATH:<directory containing the script>"
Finally, in case you missed this, don't forget to make sure the executable bit is set on the script file.

knzzz
Posts: 157
Joined: 2017/02/25 12:41:42

Re: Declaring script globally

Post by knzzz » 2017/11/25 08:06:00

Thanks to both of you it worked .

Post Reply