Quote:
Originally Posted by afiqrahim
How do I write a program that starts with entering the program's name instead of having to enter ./(DotSlash) at the beginning.
The example of the output of the program is as stated above. A little help please :-)
|
The output has nothing to do with how you start the program. In a typical Unix(-like) environment you launch an executable (in a shell) by giving (full or relative to current working directory) path to it, along with the executable filename. Certain directories are searched automatically, for example /bin, /usr/bin, and so on. This means that even if you do not give full or relative path to the executable, i.e., you simply type the executable filename, certain directories (usually listed in an environment variable $PATH) are looked into, and if an executable of the name you gave is found in one of them, it is executed from there. If it exists in multiple directories that are searched, typically it is executed from the first directory where it is found.
To get your program to run "without giving path", you either put it into a directory that is automatically searched (see directories listed in $PATH), or add the directory, where the executable is, to the list yourself. Note: while it may be possible to have the system search for the current working directory first, meaning that you could execute any file within the current directory without typing the dot-slash, it might not be wise; this would make it a lot easier to accidentally run a program, which you usually do not want to do.