LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to run programs using executable name (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-programs-using-executable-name-100688/)

ravykanth 10-05-2003 11:34 PM

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?

td_miles 10-05-2003 11:45 PM

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.


All times are GMT -5. The time now is 05:32 AM.