LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I run executables without the ./ part? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-run-executables-without-the-part-100429/)

Abdul 10-05-2003 08:08 AM

How do I run executables without the ./ part?
 
This is probably a dumb question.

I have an executable file HelloWorld in a subfolder of my home directory. I can only make it run if I include the path: ./HelloWorld. I want to make it run only by typing HelloWorld without the ./ part. Any idea how to do this? I am running the bash shell.

kaega2 10-05-2003 09:23 AM

You need the ./ in there. Otherwise linux thinks your trying to use an internal command rather then a binary file

fatgod 10-05-2003 09:30 AM

You should only have to do this as the root user, unless its some kind of debian thing, that is... I dont know about that... it's a type of safety thing.

But to answer your question...

If you want to run this file as root without having to put ./ in front then you need to put it into roots search path.

if you type "echo $PATH" then that will print out your search path and will look like this..
$ echo $PATH
/home/owen/bin:/usr/local/bin:/usr/bin:.....

So copy the file to /usr/bin or one of the dirs that are in your PATH and then you can run that file from any directory ;)

Svha 10-05-2003 09:31 AM

Its because Linux has a default search path for executable files ..... you can find the default search path from the console with the

echo $PATH

For example mine is;
/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/svha/bin

So you can either move helloworld into one of your default PATH directories, or you can add the folder that contains the helloworld program into your default path (The link should assist you with doing that)

http://www.linux-tutorial.info/cgi-b...8&9998&388&0&3

Svha

acid_kewpie 10-05-2003 09:36 AM

as above it is a path issue. i'd advise you to try to go with the flow where possible though, don't fight the linux conventions, as they are there for very good reasons. if you do add anythign to it, please try to use a fixed bin/ directory, not your home directory or such like.

Quote:

You need the ./ in there. Otherwise linux thinks your trying to use an internal command rather then a binary file
Sorry, but that is very wrong...

Abdul 10-05-2003 11:37 AM

Ah well guess Ill just get used to it, helloworld probably isnt important enough to dump in the shared binaries folder. Thanks for the help.

quatsch 10-05-2003 11:47 AM

you could also just place a symlink to it in /usr/bin.

rahulsundaram 10-05-2003 10:43 PM

hi

this is a security feature. if you have a program you created which you called ls and which actually deletes files. if you just type ls the internal command will get executed. if you type ./ls your program will get executed. so you know which one is yours and which one is built in. it will prove very useful if you are system admin. even if you are not this is a safety feature. you can add the current directory to the path but dont do it

regards
rahul sundaram

dekket 10-06-2003 12:22 AM

Re: How do I run executables without the ./ part?
 
Quote:

Originally posted by Abdul
This is probably a dumb question.

I have an executable file HelloWorld in a subfolder of my home directory. I can only make it run if I include the path: ./HelloWorld. I want to make it run only by typing HelloWorld without the ./ part. Any idea how to do this? I am
running the bash shell.

No problem, do a symlink in your $PATH, such as /usr/bin/..
basically;
# cd /usr/bin
# ln -s /home/username/HelloWorld/whatever helloworld

That'll do it.
Or you can just move/copy the HelloWorld thingie to /usr/bin/.

Good luck.

Edit: oh sry, didn't notice the previous post about it... ;)

miknight 10-06-2003 12:40 AM

Quote:

Originally posted by acid_kewpie
don't fight the linux conventions, as they are there for very good reasons.
This is true - and they're not just Linux conventions, they're part of the POSIX standard (i.e. basically a UNIX convention).

One of the exciting things about using a new OS is that you learn to work with all its new aspects, not trying to clone it into a WIndows-like system.

If there's something you need done repetitively, try writing a script to do it. Also, tab completion is your friend :)


All times are GMT -5. The time now is 05:42 PM.