Fedora Linux Support Community & Resources Center
  #1  
Old 15th April 2012, 06:21 PM
Programmer Offline
Registered User
 
Join Date: Apr 2012
Location: Kashan
Posts: 31
linuxchrome
Question Starting programs in shell

I'm new in Linux and I have a problem with a little thing :

For example when I type this in terminal :
Code:
$ cp file.ext /lib/
I pass some arguments to a program called "cp" and it parsing the arguments and in this example it copy a file to a path

I found that some apps that I use in terminal are located in /bin folder and I can access every file that is in /bin folder directly and global

But some apps are not in /bin folder but I can use them in terminal ( for example yum ):confused
In windows there is a variable called PATH that Can be used for make a folder global
has Linux something like this ?

My question is how Linux do it ? I mean how does it recognize the apps that we use in terminal ?

For example I have a file in path :
Code:
 /apps/
named exam.py
I want that when I use
Code:
$ exam my args
in terminal this file pass to python interpreter and then execute
like :
Code:
$ python /apps/exam.py
?
Reply With Quote
  #2  
Old 15th April 2012, 06:45 PM
Misfit138 Offline
Registered User
 
Join Date: Feb 2011
Location: USA
Posts: 42
linuxchrome
Re: Starting programs in shell

You can manipulate a user's path by editing his ~/.bash_profile file. Add directory paths separated by colons and with no intervening space.
For example
Code:
export PATH=$PATH:/sbin:/usr/sbin:/usr/bin
export PATH
For root it would be /root/.bash_profile.

Fedora seems to merge /etc/profile on updates, so it seems modifying it is not recommended, though I view it as a more conventional file for global path to be set. You may wish to heed the instruction to create a custom.sh under /etc/profile.d as recommended in that file.
__________________
“There are two ways to get enough. One is to continue to accumulate more and more. The other is to desire less.”
― G.K. Chesterton

Last edited by Misfit138; 15th April 2012 at 06:50 PM. Reason: correction tech
Reply With Quote
  #3  
Old 15th April 2012, 06:52 PM
Programmer Offline
Registered User
 
Join Date: Apr 2012
Location: Kashan
Posts: 31
linuxchrome
Re: Starting programs in shell

Can you say how can I do the example that I said ? ---> exam.py
Reply With Quote
  #4  
Old 15th April 2012, 07:15 PM
Misfit138 Offline
Registered User
 
Join Date: Feb 2011
Location: USA
Posts: 42
linuxchrome
Re: Starting programs in shell

Edit your user's /home/user_name/.bash_profile file and add /apps/ after a colon to the PATH= line.
You'll need an editor, of course. gedit, nano, kwrite, kate, vim and joe are examples of editors. Use whichever one you feel comfortable with.
__________________
“There are two ways to get enough. One is to continue to accumulate more and more. The other is to desire less.”
― G.K. Chesterton
Reply With Quote
  #5  
Old 15th April 2012, 07:36 PM
Gareth Jones Offline
Official Gnome 3 Sales Rep. (and Adminstrator)
 
Join Date: Jul 2011
Location: Birmingham, UK
Age: 32
Posts: 2,771
linuxfirefox
Re: Starting programs in shell

Quote:
Originally Posted by Programmer View Post
But some apps are not in /bin folder but I can use them in terminal ( for example yum ):confused
In windows there is a variable called PATH that Can be used for make a folder global
has Linux something like this ?
Others have already answer about PATH, so I'll just add that you can see the current PATH by entering "echo $PATH" into the shell.

The standard directories for software (which should always be in PATH), are /bin (core programs), /usr/bin (the rest of the system), and /usr/local/bin (programs that are not installed by the package manager, e.g. things you've compiled yourself). There are also sbin directories containing administration programs. In F17, /bin and /sbin are going to be replaced with symbolic links to their /usr equivalents.

Occasionally programs are installed in other places, such as /opt/package_name (self-contained packages), ~/bin and ~/.local/bin for personal scripts etc. Also, some commands are shell built-ins, shell aliases or shell functions, and these don't correspond to files.
Reply With Quote
  #6  
Old 15th April 2012, 09:40 PM
SteveGYBE Offline
Registered User
 
Join Date: Jun 2007
Location: Lytham St Annes, Lancashire, UK
Posts: 338
linuxfirefox
Re: Starting programs in shell

There is the utility "which" which prints out where it finds the program on your path
Code:
$ which yum
/usr/bin/yum
Yum is a good example, because it's a Python script
Code:
$ file /usr/bin/yum
/usr/bin/yum: a /usr/bin/python script, ASCII text executable
Although it's ASCII text - it is marked as executable
Code:
$ ls -l /usr/bin/yum
-rwxr-xr-x. 1 root root 801 Mar 16 19:11 /usr/bin/yum
The system knows it should be run using Python by the special entry in the first line of the file (#!' is not a comment, but indicates that the command interpreter to use follows)
Code:
$ cat /usr/bin/yum
#!/usr/bin/python
import sys
try:
    import yum
except ImportError:
    print >> sys.stderr, """\
 [ . . . ]
So if you want to run "exam my args":
  • Call your file "/apps/exam" (unlike Windows, Linux will not try to guess the file extension of your command, but simply look for what you call it)
  • Mark it as executable "chmod a+x /apps/exam"
  • Add "/apps" directory to your path "export PATH=$PATH:/apps"
  • Add the first line telling it to run the commands using python "#!/usr/bin/python"
Reply With Quote
  #7  
Old 16th April 2012, 12:41 PM
Programmer Offline
Registered User
 
Join Date: Apr 2012
Location: Kashan
Posts: 31
linuxchrome
Talking Re: Starting programs in shell

Thanks every one
Reply With Quote
Reply

Tags
programs, shell, starting

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell programs friar_tux Using Fedora 1 9th October 2009 03:47 PM
Programs Not Starting Up. baba ganoush Using Fedora 21 11th December 2008 03:20 PM
background programs and exiting the shell joskaefer Using Fedora 2 11th August 2006 05:30 PM
Long delays starting up, and starting most programs. LionKimbro Using Fedora 0 4th May 2006 03:21 PM
starting programs on boot desipher Servers & Networking 3 16th September 2005 11:53 PM


Current GMT-time: 02:13 (Tuesday, 21-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Bedlington Photos - Marechal Candido Rondon Travel Photos on Instagram - Ferkessedougou Travel Photos on Instagram