box
Create a text file called box.c that contains the following C program:#include <stdio.h> int main() { printf ("\t***\n"); printf ("\t***\n"); printf ("\t***\n"); return 0; }Save the file and then compile the program:
gcc box.c -o boxAssuming you copied the program correctly, the compiler will translate box.c successfully. Run the program:
./box
"./box"
rather than simply
"box"
. The
preceding "./"
is used to tell Unix which directory to look in for the
executable program: the dot means "here" (current directory).
It may seem strange but, in fact, the Unix shell does not normally look for
executable programs in the current directory.
However, your system may be configured to search the current directory
(i.e. "."
) in which case you can leave out the preceding
"./"
and run the program by just typing "box"
.
At the shell prompt type in the command:
echo $PATHand have a look at what you get back. You will see a colon-separated list of directories - these are the directories that are searched for executables when a command is typed at the terminal. Now look carefully - does the search path contain "
.
"? It will look like this, ":.
",
with a preceding colon, if it occurs at the end of the search path,
or it will be surrounded by colons if it occurs somewhere else within the search
path ":.:
".
You need to add the following line to the .profile file which is found in your home directory.
export PATH="$PATH:."