bash: command not found

Asked by Margotvolta

Ok, I have used putty for a little while now. I am trying to compile C code on the terminal. Actually I can get it to compile with gcc, but when I go to execute the file I see bash: hello_world.exe : command not found. What am I missing? When i type ls, it pulls up the file. I chose hello world only bc it is such a basic program.

#include <stdio.h>
int main ()
{
    printf("\n Hello World");
    return 0;
}

margot@margot:~$ pico hello_world.c
margot@margot:~$ gcc hello_world.c -o hello_world.exe
margot@margot:~$ hello_world.exe
bash: hello_world.exe: command not found
margot@margot:~$ ls
Desktop Examples hello_world.c Logs nautilus-debug-log.txt p4_factorial_loops.exe Public Videos
Documents Firefox_wallpaper.png hello_world.exe Music p4_factorial_loops.c Pictures Templates
margot@margot:~$

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Solved by:
John Clarke
Solved:
Last query:
Last reply:
Revision history for this message
Best John Clarke (jrc61) said :
#1

The shell (bash) searches the directories listed in $PATH when looking for an program to run. Unlike DOS/Windows, the current directory (".") is not in $PATH, and it can't find hello_world.exe in any of the directories that are in $PATH.

You should be able to run your program by entering "./hello_world.exe". If you give bash the absolute path ("/home/margot/hello_world.exe") or a path relative to the current directory ("./hello_world.exe"), then it will run the program without using $PATH.

It's not normally a good idea to add the current directory to your path, but if you really want to do it, edit $HOME/.bash_profile (or if it doesn't exist, edit $HOME/.profile) and add this at the end of the file, then logout and log back in again:

    PATH="$PATH:."

If you want the current directory to be searched before any other directories, add this instead:

    PATH=".:$PATH"

Note that the directories are separated by colons, rather than semi-colons as used by DOS/Windows, and are searched in left-to-right order until the required program is found.

Revision history for this message
Margotvolta (margotvolta) said :
#2

Thank you so much...I knew it would be as simple as "./" Greatly
appreciated. Now I can move on to bigger and better programs. ;)

On Tue, Aug 26, 2008 at 12:22 AM, John Clarke <
<email address hidden>> wrote:

> Your question #43203 on gnome-terminal in ubuntu changed:
> https://answers.launchpad.net/ubuntu/+source/gnome-terminal/+question/43203
>
> Status: Open => Answered
>
> John Clarke proposed the following answer:
> The shell (bash) searches the directories listed in $PATH when looking
> for an program to run. Unlike DOS/Windows, the current directory (".")
> is not in $PATH, and it can't find hello_world.exe in any of the
> directories that are in $PATH.
>
> You should be able to run your program by entering "./hello_world.exe".
> If you give bash the absolute path ("/home/margot/hello_world.exe") or a
> path relative to the current directory ("./hello_world.exe"), then it
> will run the program without using $PATH.
>
> It's not normally a good idea to add the current directory to your path,
> but if you really want to do it, edit $HOME/.bash_profile (or if it
> doesn't exist, edit $HOME/.profile) and add this at the end of the file,
> then logout and log back in again:
>
> PATH="$PATH:."
>
> If you want the current directory to be searched before any other
> directories, add this instead:
>
> PATH=".:$PATH"
>
> Note that the directories are separated by colons, rather than semi-
> colons as used by DOS/Windows, and are searched in left-to-right order
> until the required program is found.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
>
> https://answers.launchpad.net/ubuntu/+source/gnome-terminal/+question/43203/+confirm?answer_id=0
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/ubuntu/+source/gnome-terminal/+question/43203
>
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Margotvolta (margotvolta) said :
#3

Thanks John Clarke, that solved my question.

Revision history for this message
Margotvolta (margotvolta) said :
#4

LinkedIn
------------

I'd like to add you to my professional network on LinkedIn.

- Megan

Megan Miller
Manager/Server at Luna Bar and Grill
Lake Charles, Louisiana Area

Confirm that you know Megan Miller:
https://www.linkedin.com/e/-11mmje-h1plch4l-1k/isd/6920366056/bipl1mTe/?hs=false&tok=0WOHpygcWzLlc1

--
You are receiving Invitation to Connect emails. Click to unsubscribe:
http://www.linkedin.com/e/-11mmje-h1plch4l-1k/ifEXYyPVQKF5oZj5YRF6yyW6QLpJ2S4PyoDt5yXq-JEEHWEhXHB1/goo/question43203%40answers%2Elaunchpad%2Enet/20061/I2376383199_1/?hs=false&tok=0GffsxnqqzLlc1

(c) 2012 LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.