Solved Calling commands vs. executables in CSH shell

Hello, I have a pretty basic question here.

I just wrote my first C program in FreeBSD, hello.c. After a quick cc -o hello hello.c I'm ready to run my executable, hello. So I type hello into the shell prompt but am told that the command doesn't exist.

After some poking around I found that typing ./hello produces the desired result. In this thread I am looking for an explanation on this. Do you always need to specify the directory of an executable file to run it, even if it is located in the current working directory?

Also, if it's not too much to ask, what then is the difference between executable files and shell commands? For example, I can use shell commands like ls and cd without specifying their location in the file system.

Thanks for your time!
-Squidward
 
The shell searches the directories specified by the environment variable PATH for executables if you don't specifically specify a path (like you did with ./hello).
Type printenv PATH into your shell to look at the current value of that variable. Also take a look at environ(7) to learn more about it.
Also, if it's not too much to ask, what then is the difference between executable files and shell commands?
Some commands are shell builtins either for performance reasons, control flow, or when they change the state of the shell like cd (see builtin(1) for a list of builtin commands). If the command does not match any shell builtin it is looked up in PATH.
 
Try to add this in .cshrc file on your home dir to the end of ENVironnement variable PATH : ./ (just a point + /)
This may not be a good idea in the general sense as a typo may run a command you didn't intend depending on where you are. However with rehash being required in tcsh(1) I don't think that would actually work.
 
This may not be a good idea in the general sense as a typo may run a command you didn't intend depending on where you are.
It's an age-old security risk, the idea being that someone puts a program with the same name as a common command in a shared directory.
 
Back
Top