Find the answer to your Linux question:
Results 1 to 3 of 3
I've compiled a c program in Linux with the following command: gcc hello.c When I type "a.out" and try to execute it, it says: bash: a.out: command not found. But ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    16

    Question [SOLVED] bash: a.out: command not found.

    I've compiled a c program in Linux with the following command:
    gcc hello.c

    When I type "a.out" and try to execute it, it says:
    bash: a.out: command not found.

    But I can see the a.out file in the folder.

    By searching the internet I know I can use "./a.out" to execute it.

    Why do I need to use "./a.out" instead of "a.out"?

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by warrentang View Post
    Why do I need to use "./a.out" instead of "a.out"?
    Bash tries to execute commands based on your PATH. It's an environment variable that tells Bash where to find programs. Usually your PATH points to /bin/ and /usr/bin/ and perhaps a few other directories. Bash can't find a.out in those directories, so it throws an error.

    By prefacing a command with ./ you're telling Bash to include the current directory you're working in when it looks for the executable named "a.out".
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    16
    Thank you for that info!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...