0

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?

1

4 Answers 4

8

./ 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.

2
  • 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, 2011 at 19:22
  • There are also good reasons to not put . in your PATH.
    – snakehiss
    Oct 11, 2011 at 4:43
4

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.

3
  • 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, 2011 at 15:14
  • 1
    It's somewhat okay to add . at the end of $PATH. Still not recommended, though. Oct 10, 2011 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, 2011 at 19:23
2

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.

0

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.

You must log in to answer this question.

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