Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Running a.out

Running a.out
Thread Tools
Moderator
Join Date: Sep 2000
Location: Irvine, CA
Status: Offline
Reply With Quote
Apr 6, 2001, 09:22 PM
 
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
Reply With Quote
Apr 6, 2001, 10:04 PM
 
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
Reply With Quote
Apr 7, 2001, 12:56 AM
 
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
Reply With Quote
Apr 7, 2001, 03:19 AM
 
Thanks for the help. Much appreciated.
{{{ mindwaves }}}
     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Apr 7, 2001, 09:19 AM
 
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
Reply With Quote
Apr 7, 2001, 11:24 AM
 
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
Reply With Quote
Apr 7, 2001, 02:21 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2