gcc compile on cmd line, then run, get: bash: hello: command not found

This is a discussion on gcc compile on cmd line, then run, get: bash: hello: command not found within the Linux Programming forums, part of the Platform Specific Boards category; I'm simply trying to compile and run a c program from command line in Linux Red Hat 7.2. Here are ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    8

    Unhappy gcc compile on cmd line, then run, get: bash: hello: command not found

    I'm simply trying to compile and run a c program from command line in Linux Red Hat 7.2. Here are my steps:

    1. I compile a simple hello world program using this:

    gcc -g -Wall -ansi -pedantic -ohello -hello.c

    2. It runs through just fine, no errors or warnings, so then at the command line, I enter simply:

    hello

    3. And it tells me:

    bash: hello: command not found

    All I want it to do is spit out, "Hello World" and it won't... so maybe I'm in the wrong shell, or I have to put a command in that says execute hello or maybe the compile command used isn't actually creating an executable. As you can see, I'm very new to this. Got any suggestions?
    Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    type
    ./hello

    You could put . in your $path, but that is generally considered to be a security risk.

    > or maybe the compile command used isn't actually creating an executable
    Do an 'ls' to find out then
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    8
    ahhh yes... thanks for that.... it works just fine... so precise. Have to tell it which directory it's in I guess.

  4. #4
    Unregistered
    Guest
    >>Have to tell it which directory it's in I guess.<<

    exactly...like salem said. you can change your $PATH enviroment varible to include the current directory, but it's typically not done.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    but it's typically not done
    Yes, it is considered a possible security risk. Many Windows worms use the current directory loophole. I don't know how, that's just what I've read.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Line Counting
    By 00Sven in forum C Programming
    Replies: 26
    Last Post: 04-02-2006, 08:59 PM
  3. makefile
    By twans in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2005, 12:16 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21