Saturday, April 27, 2024
40
rated 0 times [  40] [ 0]  / answers: 1 / hits: 121802  / 3 Years ago, tue, july 13, 2021, 6:18:44

I just switched from Windows to Ubuntu 11.10.



I wrote the following code in C with the text editor and saved it as HelloWorld.c in Documents.



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


And I started the Terminal and enter the following commands:



cd Documents

gcc HelloWorld.c


A file called a.out, which, after some search on Google, is the executable. I entered this command:



a.out


But I get



a.out: command not found


Which step did I do wrongly?


More From » command-line

 Answers
5

Since you're running an executable in the current working directory, you should prefix it with ./. So for your program run it as ./a.out.



Explanation



The terminal searches for executables in $PATH. This is a Unix environment variable that lists directories containing system binaries (such as ls, echo, or gcc). If you call an executable that's not in a $PATH directory (such as a.out), you need to indicate its absolute path in the file system.



In the terminal . is a synonym for the current working directory, thus ./a.out. You could equally well call /home/yihang/Documents/a.out.


[#39975] Tuesday, July 13, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
biryanrownies

Total Points: 396
Total Questions: 90
Total Answers: 106

Location: Saint Lucia
Member since Sun, Sep 5, 2021
3 Years ago
biryanrownies questions
Wed, Sep 7, 22, 18:13, 2 Years ago
Fri, Dec 3, 21, 02:50, 2 Years ago
Sat, Feb 12, 22, 16:02, 2 Years ago
Sat, Apr 15, 23, 09:22, 1 Year ago
;