LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 08-24-2008, 08:01 PM   #1
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
How do you enable a shell script to be runnable in any directory?


Do I move the shell script to /usr/bin or /usr/local/bin to be able to use it in any directory?

Thanks
okos
 
Old 08-24-2008, 08:09 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
If you mean you simply want to invoke the script as you would most system executables:

scriptname

rather than:

/path/to/scriptname


or

./relative/path/to/scriptname

then all you have to do is put it in /usr/local/bin and ensure that all users have /usr/local/bin in their PATH environment. I suggest /usr/loca/bin because it makes life a little easier to maintain - if you put it in /usr/bin it's lost with hundreds of other scripts and executables. I would also suggest keeping a list of such programs which are not installed by yoru package manager - that way you know what you installed and where and can delete if you decide you no longer want it.
 
Old 08-24-2008, 08:28 PM   #3
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 32
If you want all users on the computer to be able to execute a program, you can copy it or link it in either of those directories (/usr/bin or /usr/local/bin).

If you are the only person that runs this program, you can place it in '~/bin'; this is your bin directory in your home directory('~' is short for the path to your home directory in any shell, aka /home/yourname). It may or may not already be there. If it's already there, it's probably already set up and all you need to do is copy/link the program to that directory. Try it in this order:

1. Check to see if ~/bin is already there:
Code:
cd ~/bin
If it gives an error, then it's not set up, otherwise you probably only need to copy program to it.

2. To set it up:
Code:
mkdir ~/bin
echo export PATH=~/bin:\$PATH >> ~/.bashrc
All new terminals should now be able to call programs in the ~/bin directory.

Good luck and post back if you have any more problems!
 
Old 08-25-2008, 12:35 AM   #4
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by CRC123 View Post

To set it up:
Code:
mkdir ~/bin
echo export PATH=~/bin:\$PATH >> ~/.bashrc

Thank you guys for the response.

Three questions,
1. I assume this is done my me and not root since it would be in my home directory.

2. Could you explain the syntax for
Code:
echo export PATH=~/bin:\$PATH >> ~/.bashrc
I understand that it is telling bash that there is another bin directory in my home directory. I dont just want to mindlessly copy the command without actually understanding the syntax.

3. Putting the script in the /usr/local/bin enables all users? I assume ownership of the script will also determine which user can execute the script. Correct?

Thank you
okos

Last edited by okos; 08-25-2008 at 12:39 AM.
 
Old 08-25-2008, 12:47 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Hopefully CRC123 doesn't mind me responding to these.

Quote:
Originally Posted by okos View Post
1. I assume this is done my me and not root since it would be in my home directory.
Yes.

Quote:
2. Could you explain the syntax for
Code:
echo export PATH=~/bin:\$PATH >> ~/.bashrc
I understand that it is telling bash that there is another bin directory in my home directory. I dont just want to mindlessly copy the command without actually understanding the syntax.
All it does is to put the line "export PATH=~/bin:\$PATH" in .bashrc. "export PATH=~/bin:\$PATH" simply adds ~/bin to the list of directories in PATH.

Quote:
3. Putting the script in the /usr/local/bin enables all users? I assume ownership of the script will also determine which user can execute the script. Correct?
All users will be able to execute it if the permissions are set properly. Ownership doesn't necessarily determine which user can execute it. You might like to read about permissions.
 
  


Reply



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 enable auto login using a shell script gauravtiwari21 Linux - Security 4 10-20-2007 02:55 AM
shell script - process directory keith2045 Programming 7 05-31-2007 07:26 PM
Making a shell script to enable/disable apache/mysql Lazy Foo' Programming 2 01-27-2006 09:07 AM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:43 PM.

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
Open Source Consulting | Domain Registration