packman
10-01-2002, 01:07 AM
it's embarrasing to ask but what the heck...
I've been using unix for my c class on campus and finally installed linux last week. After i compiled something that creats... say a.out without specifying file name.
To run it, i used to just type "a.out" to run. But it doesn't work on my computer... I get message that a.out: command not found.
What can I do?
Thanks
bwkaz
10-01-2002, 11:31 AM
Yep. You need to specify where the a.out file is at. On the Unix machines you've been using, they've probably set it up so that the current directory (.) is in your $PATH variable. You can do that if you want, but it's a security hole if you have >1 user on the machine ever. Or if someone finds a remote access exploit and can get a shell on your machine. They create a shell script called ls (or some mistyping thereof that you do frequently; it all depends on where . is in your $PATH) and put it in /tmp. They wait until you change into /tmp and try to list what's there, perhaps mistyping. If your $PATH has . before /bin, then they can name it ls, because the shell will look in the current directory first. If . is at the end of $PATH, they name it some mistyping of ls. What they do in the script is:
1) Create a user that they can later log in as, and assign it a password
2) Make that user's UID zero (so he's effectively another "root")
3) Emulate what normally would have happened. If they named the script ls, they would call /bin/ls with the rest of their command-line args, so you wouldn't notice any difference. If they named it a misspelling of ls, they'd print out "bash: $0: command not found" to stderr, so again, it would look normal ($0 is the command you typed, misspelled).
4) Delete the script itself
Then they can log in as a root user to your machine. Losing the . from your PATH is generally a really good idea.
nuvan
10-01-2002, 08:03 PM
if you want to change the name of the output file, just compile like this:# gcc foo.c -o foo this will tell it to name the output foo.
and like the others have said, to run it, you need to type # ./foo unless . is in your $PATH