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
Declaring script globally
Re: Declaring script globally
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
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
Re: Declaring script globally
1. You should set the PATH to include only the directory that contains the script you want to run, not the script itself.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
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>"
Re: Declaring script globally
Thanks to both of you it worked .