Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My OS is Fedora Linux 14.

I write a program with Code::Blocks IDE and it compiles my program with GCC.

My output program is test. When I start my application in Code::Blocks it starts normally. But when I double click on my executable program, the program does not starts. When I start a terminal (in path of my binary program), and type test, my program does not starts, but whrn I type ./test in terminal, it starts normaly. Why I should type ./ when I want running an application?

share|improve this question

migrated from stackoverflow.com Oct 10 '11 at 14:44

This question came from our site for professional and enthusiast programmers.

up vote 8 down vote accepted

./ is necessary when your PATH environment variable does not include the current directory. So if you have an executable in some directory that is not on your path, you need ./theexecutable to tell the shell that your executable is in the current directory.

share|improve this answer
2  
Even if . is in the path if /bin/ is before . in the PATH it will not execute test. /bin/test exists (see the man page). Avoid calling your test program "test" to avoid confusion. – Matteo Oct 10 '11 at 19:22
    
There are also good reasons to not put . in your PATH. – dietbuddha Oct 11 '11 at 4:43

Simply because the current directory ., is normally not included in the PATH variable.

If you don't what to type ./, you could add . to the colon separated list of folders contained in PATH, however is not recommended, because it would be easy to mask system commands without realising it.

share|improve this answer
    
Rather than adding ".", I would instead add the specific directory your programs are compiled in, e.g. ~amir/codeblocks/executables. (I have no idea if that's the right directory but I hope I have gotten the idea across.) – CarlF Oct 10 '11 at 15:14
1  
It's somewhat okay to add . at the end of $PATH. Still not recommended, though. – grawity Oct 10 '11 at 16:03
    
@grawity At the end will not work in this case /bin/test/ exists and will be executed instead of ./test since /bin/ will be before the current did. I would not call my test program test (a common unix utility) – Matteo Oct 10 '11 at 19:23

When you just type the program name, *nix will look through all your PATH locations for that name. If it doesn't find it, it won't start. So you must enter "./" to indicate the current directory.

share|improve this answer

In addition to what the other answers tell you:

When you type test, you're probably invoking /bin/test; man test for details.

When you double-click on the executable (from nautilus or something similar, yes?), it probably does run, but without a terminal you can't see the output.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .