Log in

View Full Version : Linux


jduke44
Sep 29, 2005, 05:38 PM
I am using VI editor at work to try to compile my programs for school in C. When I compile I get the file a.out. When I do this on the school's site I am able to just type a.out in the command line and it runs. They are using AIX (whatever that means). I cannot do that here. It keeps saying no such file. I am using Linux, that is about all I know. Can anyone point me in the direction to be able to run my file after compiling it. I hope I gave you all the info. Unfortunately I am not that familiar with Unix. Thanks. :confused:

LTheobald
Sep 29, 2005, 10:47 PM
http://users.actcom.co.il/~choo/lupg/tutorials/c-on-unix/c-on-unix.html

Looks like it's just a case of typing what you would to run a normal program in Linux - a full stop, followed by a forward slash, then the program name. So in your case:

./a

I don't think you need the .out at the end. Also, note the tip in the "Compiling A Single-Source C Program" about how to rename your programs to something more useful than "a.out"

psi42
Sep 29, 2005, 11:08 PM
Just to add to that:

1) You do need to type ./a.out, not just ./a (unlike DOS, *nix shells don't do silly things).


When I do this on the school's site I am able to just type a.out in the command line and it runs.


This is (probably) because of the environment variable $PATH, which defines where your shell looks for commands that you type that aren't builtins. $PATH contains a list of directories to search. Either the directory where you compile and run stuff is in $PATH, or $PATH contains the current working directory "." (which is generally a bad idea).

When you want to run a command that is not in $PATH, you need to specify an absolute or relative path. Since "." denotes the current directory, typing ./a.out tells your shell to execute the file a.out in the current directory.


Alternatively, you can modify $PATH to include the place where you compile stuff:

How you set $PATH depends on your shell, but on most (I think all) Bourne-compatible shells you should be able to do something like.


PATH=/usr/bin:/bin:/some/other/path:/path/to/foo
export PATH


In your case, you'd want to keep the stuff already in $PATH, so you could do


PATH=$PATH:/path/to/where/your/binaries/are
export PATH




They are using AIX (whatever that means).


AIX is IBM's proprietary UNIX operating system.



~psi42

jduke44
Sep 30, 2005, 01:31 PM
Thanks guys for your help. The admin at work fixed it for me. I was trying to see if I could get an answer before I went home last night. It was to do with the path. As you probably already guessed I don't know much about Unix. I want to learn. This helps my knowledge base if anything. Thanks again.