a.out file

Im not sure about it, but why can not I create two a.out files in the same directory?
how to run a.out file without command line ./a.out?
Last edited on
Im not sure about it, but why can not I create two a.out files in the same directory?
Are you serious?
how to run a.out file without command line ./a.out?
You can place it in the path. If it's not in the path, you have to name the path (full or relative) to the executable. ./ is a relative path to the current directory.
> Im not sure about it, but why can not I create two a.out files in the same directory?
I guess you can use the -o option of gcc to rename the executable.

gcc -o foo foo.c
gcc -o bar bar.c


Then you can do ./foo or ./bar as much as you like.

As a side note to kbw's point about the path, resist the temptation to put '.' in your PATH variable.
It's generally considered to be a security fail if you do so.
https://unix.stackexchange.com/questions/548083/what-is-the-use-of-adding-dot-in-path-variable
you can't have 2 files with the same name in a folder. Doing so, if it were allowed, would cause all kinds of problems.... if you had 2 in theory because it were allowed, how do you run one of them ... and only one of them, but not both, and which one do you run, and how do you tell them apart?

you can add your current folder where you work to the system path so it is searched for programs, or you can add the . (as noted there are risks), or you could make a shell script to run it, and probably other magic tricks as well.

Building off of what others have said, you can compile to foo and to bar, then place those files in ~/bin/
where ~/ is your home directory and bin is short for the word binaries. (this essentially installs them on your system in a way that can only be used by your user name). Then you can call them just like any other terminal program.

Some distros have this "local bin" already set in the path environment variable, but you can check if it is by calling "echo $PATH". If it is not in your path, then you can edit your .bash_profile or .bashrc file to add it in there. (there's a lot of tutorials on how to set that up, so try a simple google search). You may also have to call "mkdir bin" if that folder does not exist yet.

If you do edit your .bashrc file, you might also like to look up how to create aliases which are helpful shortcuts for calling files with options that you specify beforehand.

Last edited on
Registered users can post here. Sign in or register to post.