Running compiled program in Ubuntu

Posted on 2011-04-30
Medium Priority
Last Modified: 2012-05-11
Hey Experts,

I have a problem with my Ubuntu install. When I compile a program I get some runnable code that is in a file called a.out. I can't simply type


in the terminal because it won't run. I need to type


and it will run fine. How do I make it so I don't have to type a dot and a slash before running code?

Question by:jeffiepoo

Expert Comment

ID: 35499407
Set your PATH variable in the environment to include the directory where the file is being created.


LVL 68

Accepted Solution

woolmilkporc earned 2000 total points
ID: 35499964
That's because the current directory (the dot "." is a hard link to the current directory) is not in your PATH.


... either add the dot to your PATH (which is not really recommended for security reasons):

export PATH=$PATH:.

Add the above to your $HOME/.profile shell initialization file at the end.

... or put your executables in a common place like /usr/local/bin (create this directory if needed) and add it to your PATH:

export PATH=$PATH:/usr/local/bin

Again, add this to your $HOME/.profile shell initialization file at the end.

Now logout/login again to make the new setting active, or issue the desired statement from above from the commandline for a temporary change lasting until the next logout/login.



Expert Comment

ID: 35499973
Or you can type this in the terminal: "gcc program.c; ./a.out" (if you don't use gcc, you'll have to modify it)
It compiles and runs the program automatically.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 62

Expert Comment

ID: 35501462
excluding current directory from executables path is a security measure.

Author Comment

ID: 35774740
Whoever marked this as abandoned is dumb. It isn't even 3 weeks old. I just haven't gotten to trying out the suggestions. Thx
LVL 62

Expert Comment

ID: 36950717

normally yo make a makefile which would call

$CC x.c -o bin/x

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question