LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Best way to execute a script ? (https://www.linuxquestions.org/questions/linux-newbie-8/best-way-to-execute-a-script-815954/)

ssvirdi 06-23-2010 01:04 PM

Best way to execute a script ?
 
There are many ways to execute a script (*.sh). But what is the best way to execute a script also what should be its location. So that it can be executed from anywhere in the shell. I don't want to execute them with ./*.sh.


thanks in advance

repo 06-23-2010 01:08 PM

I put them in
Code:

/usr/local/bin

ssvirdi 06-23-2010 01:17 PM

thanks for ur answer

if I create a folder in /usr/local/bin/ and put all scripts in that folder.

is it ok or not.

repo 06-23-2010 01:19 PM

no, just put them in
/usr/local/bin
If you create a folder, you need to add the folder to your PATH
/usr/local/bin
is already in your PATH

ssvirdi 06-23-2010 01:24 PM

thanks

Davno 06-24-2010 08:15 AM

I myself have my script in a /home/user/script_folder since 2 different users have there own personnel backup script on the main computer it is more convenient.

ssvirdi 06-24-2010 09:43 AM

thanks Davno

can you please describe, how to make them executable like other commands if I copy scripts in /home/ssvirdi/myScripts.

i92guboj 06-24-2010 10:09 AM

"Where" to put them is one question. You can put them anywhere as long as the location is included in your $PATH, to see the current value of $PATH just use this:

Code:

$ echo $PATH
There are other factors that can prevent the scripts from running, for example, if the partition that holds that location is mounted with the "noexec" mount option. Also note that other options ("user" rings a bell) imply "noexec". By default, on most distros, /usr/local/bin is in the system $PATH, but that's not necessarily true in all distributions.

"How" to modify your $PATH to include any arbitrary location is an entirely different question, and that depends on the shell you use. Most of them will read /etc/profile, per-user settings are defined in each shell init files, for bash that can be ~/.bash_login, ~/.bashrc or ~/.bash_profile depending on what do you exactly want to do. Other shells will use different config files, so, check your $SHELL man/info page or documentation.

Bassby 06-24-2010 10:15 AM

Quote:

Originally Posted by ssvirdi (Post 4013662)
thanks Davno

can you please describe, how to make them executable like other commands if I copy scripts in /home/ssvirdi/myScripts.


PATH="$PATH":/home/ssvirdi/myScripts

.


All times are GMT -5. The time now is 09:10 AM.