LinuxQuestions.org
Help answer threads with 0 replies.
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 10-06-2003, 12:34 AM   #1
ravykanth
Member
 
Registered: Sep 2003
Location: Houston
Distribution: Red Hat 9
Posts: 36

Rep: Reputation: 15
How to run programs using executable name


I know this issue has been posted in earlier threads. But just wanted to understand a bit more...since I am a newbie as far as Linux is concerned.
I have an executable SumAvg (created from main.cpp) which runs if I use ./SumAvg as root and doesn' run unless I use the full qualified path name of the executable as another user. Even as root "./" works only if I am in the directory of the executable not aywhere else.
I read on some website that someone was able to make the Shell look into the current directory when running a program, by editing .bashrc. So is this possible and if yes...how will the code differ from that of root to another user?
 
Old 10-06-2003, 12:45 AM   #2
td_miles
Member
 
Registered: Sep 2003
Location: Australia
Distribution: RedHat
Posts: 51

Rep: Reputation: 15
It's all to do with PATH's.

"./" means "this current directory", so that when you use this to precede the file, it tells the OS to execute that file with that name that is in the current directory.

If you are familiar with the windows implementation of the PATH variable, then Linux is similar.

My Windows PATH variable looks like this:

Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRAM FILES\THINKPAD\UTILITIES;C:\PROGRA~1IBM\CLIENT~1;C:\PROGRA~1\IBM\CLIENT~1\Shared;C:\PROGRA~1\IBM\CLI ENT~1\Emulator;

What this means, is that when I try to run a command (and I don't specify the directory) MS windows will look in each of the locations specified in my "path" variable for that executable file. If it doesn't find the executable, and the file is not in the current directory then you get the error "command not found" (or similar).

Linux has the exact same functionality. The path statement on Linux might look like this:

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

which gives you the directories that linux will look in for an executable.

One of the quirks of Windows v's Linux is that by DEFAULT Windows will look in the directory you are currently in for an executable, without having to specify the current directory in the PATH. Linux doesn't do this. If the file is in the current directory, then you need to explicitly specify this using the "./" reference.

With both OS, if the file isn't in any of the dir's specified in the PATH statement, then you will need to give the OS the FULL path to the executable file, so that it can find it.

The command to view the environment variables (including PATH) on both OS is "set" by itself, which will display all of the current environment variables. Just scroll up to find the PATH variable.
 
  


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
executable programs petezilla Linux - Newbie 6 04-13-2005 07:36 PM
How to run an executable from browser ??? dileepkk Programming 2 08-22-2004 04:13 AM
an executable that does not run jgoggel Programming 2 07-22-2004 08:54 PM
run executable files ZeRo69er Linux - Software 4 08-07-2003 03:26 AM
How do I run my executable?? scott7500 Programming 2 12-30-2001 05:22 PM

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

All times are GMT -5. The time now is 11:06 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