 |
 |
Running a.out
|
 |
|
 |
|
Moderator 
Join Date: Sep 2000
Location: Irvine, CA
Status:
Offline
|
|
Ok, I am new to Unix. I compiled a small C program using cc filename.c. Next, I ran an a.out and it said "command not found." What am I doing wrong?
|
|
{{{ mindwaves }}}
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status:
Offline
|
|
Short answer:
type ./a.out if you are in the same directory, or /Users/absolute/path/a.out if you are somewhere else. Also, for help with drilling down paths, type the first letter of the directory you want and hit <tab> it will finish the folder name for you.
Long answer:
This is a security feature, believe it or not. Programs only run without ./ if they are in a path of the path variables like /usr/bin. The ./ before the command ensures that you mean to run that particular command in that directory and not some other somewhere else in the system. That way hackers can't write a malicious program called a.out and swap it for your a.out and have you run their program instead of yours just because the bad one happened to be in one of the preset paths. Does this make sense?
thanks,
John
|
|
My life is my argument. --Albert Schweitzer
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Apr 2001
Location: Sunnyvale, CA
Status:
Offline
|
|
Although "./" should do the job most of the time, the command "pwd" will give you the full path to your current directory as well.
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Sep 2000
Location: Irvine, CA
Status:
Offline
|
|
Thanks for the help. Much appreciated. 
|
|
{{{ mindwaves }}}
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status:
Offline
|
|
Is there any sensible reason why . isn't in the path list?
|
|
All words are lies. Including these ones.
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 2001
Location: North America
Status:
Offline
|
|
Originally posted by sadie:
Is there any sensible reason why . isn't in the path list?
That's what I was trying to explain, perhaps not very well. Let me try again. If you type 'printenv' without quotes at the CLI you will get the PATH variable for that user which is the collection of paths separated by colons. Imagine that . (your current directory) was in the PATH variable. Now along comes Johnny Hacker and he writes a little program called 'ls' that does a real 'ls' to make it look legit but then erases some stuff say 'rm -r *' . Now if you had root privileges (or you had just su'ed to root) you would be giving this faked ls program root privileges which is very dangerous. Without root, rm -r would have much less effect. So by not having . in the PATH, admins and roots are forced to type ./ to ensure that they indeed wanting to run that particular program and not the one residing elsewhere like /bin where the real 'ls' lives.
If you think this is totally bogus you can reset the PATH variable using 'env' but I can't remember how to properly do that right now. See 'man env'. But make a copy of your old PATH somewhere in case!
thanks
John
[This message has been edited by SillyMonk (edited 04-07-2001).]
|
|
My life is my argument. --Albert Schweitzer
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
setenv PATH $PATH":."
that should work
it'll only work for your current session though, you might like to put it in ~/.cshrc if you want it to happen every time you login.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|