LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2010, 02:04 PM   #1
ssvirdi
Member
 
Registered: Apr 2009
Location: Ludhiana, Punjab, India.
Distribution: Ubuntu
Posts: 47

Rep: Reputation: 15
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
 
Old 06-23-2010, 02:08 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
I put them in
Code:
/usr/local/bin
 
Old 06-23-2010, 02:17 PM   #3
ssvirdi
Member
 
Registered: Apr 2009
Location: Ludhiana, Punjab, India.
Distribution: Ubuntu
Posts: 47

Original Poster
Rep: Reputation: 15
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.
 
Old 06-23-2010, 02:19 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,527

Rep: Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898Reputation: 898
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
 
Old 06-23-2010, 02:24 PM   #5
ssvirdi
Member
 
Registered: Apr 2009
Location: Ludhiana, Punjab, India.
Distribution: Ubuntu
Posts: 47

Original Poster
Rep: Reputation: 15
thanks
 
Old 06-24-2010, 09:15 AM   #6
Davno
Member
 
Registered: Mar 2004
Location: Montreal, Canada
Distribution: Mandriva 2010.2
Posts: 148

Rep: Reputation: 24
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.

Last edited by Davno; 06-24-2010 at 09:25 AM.
 
Old 06-24-2010, 10:43 AM   #7
ssvirdi
Member
 
Registered: Apr 2009
Location: Ludhiana, Punjab, India.
Distribution: Ubuntu
Posts: 47

Original Poster
Rep: Reputation: 15
thanks Davno

can you please describe, how to make them executable like other commands if I copy scripts in /home/ssvirdi/myScripts.
 
Old 06-24-2010, 11:09 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
"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.
 
Old 06-24-2010, 11:15 AM   #9
Bassby
LQ Newbie
 
Registered: May 2010
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by ssvirdi View Post
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

.

Last edited by Bassby; 06-24-2010 at 11:17 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 03:41 AM
Limited user cannot execute a script from within a script, but root can. versaulis SUSE / openSUSE 5 12-01-2008 01:08 PM
script to parse variables to curl script and execute morphix Programming 17 11-30-2007 02:27 AM
Cannot execute a script grueugene Programming 15 01-27-2005 05:50 AM
Execute a script from iptables padukes Linux - Networking 6 03-17-2002 07:15 PM


All times are GMT -5. The time now is 02:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration