Alright im very new to programming. is the command line the same thing as the command prompt and if so how do i access a program from it. if it isnt how do i access the command line.
Command line=Command prompt
To execute an executable from the command line type the name of the executable
In windows it will search for the executable in the current directory and if it doesn't exist will search each path (separated by semicolons) in the path environment string in order. To see the current path environment variable type
.
In Linux/Unix, it doesn't search the current directory unless it is in the path (security reasons). The current directory's name is specified with a '.' in all operating systems.
If the executable is in a location that is not in the current directory and not in the path but somewhere relative to it, you can specify a relative path in front of the executable name. Say the executable is called 'Bar.exe' and is in the child directory from where you are named 'Foo'. Type
or
. If it is in the parent directory, you can type
or
. You can traverse the entire directory tree relatively if you want. I.e.
will go to the parent's parent's parent's Foo's Boo directory and try and execute Bar.
You can also specify a path to the executable absolutely, which just means it is relative to the root drive (or in the case of Linux/Unix the root). I.e.
will try and execute Bar in a directory off of the C drive named Foo. Linux/Unix doesn't have drive letters, it just has a single root in its file system. This presents something that occurs only in Windows, a relative root. If your current directory is in D: drive, then if you specify \Foo\Bar, it will look for Bar in D:\Foo. If your current directory is on C: drive, it would look for Bar in C:\Foo.
In Linux/Unix, the directory separators are different from that in windows. Linux
uses the slash (/) where as the Windows uses the backslash (\) (for interest sake, the Mac used to use colon (:) but is now moved to a Unix system so uses slash).
Oh, and before I forget, to change the current directory from the command line, use cd <path>, where <path> is an absolute or relative path.
And to change the search path in Windows for all newly executed applications and command prompts, right click on "My Computer" located either on the desktop or by clicking on the Start button, go to Properties, Advanced, Environment Variables and double click on PATH in the System (affects all uses) or User (affects current user only).
You can modify the current command prompt's path by typing
- path=%path%;<new path(s)>
or
- path=<new path(s)>;%path%
. The first will tack the new paths to search at the end and so would be searched last, the last will put it at the beginning and so would be searched first.
In Linux/Unix, it is
, or
and you may have to export the path by typing
if you use a derivative of sh (ash, bash), but I'm not sure about that one as I think that it is already exported.
Boy, I bet you thought that this was a simple question, eh? ;)
For ease, just change to the correct directory and type the executable name. And if you are using Linux/Unix put the current directory in your path (.) when you are doing development, though you shouldn't have it there by default.
One other thing, if you don't like a lot of typing, you can use what is called tab completion which is you type the first letters of the directory or executable and press tab. It will try and complete it for you. Hit it again to go to the next one that matches. Unix/Linux will only complete till it becomes ambiguous, pressing a second time may get you a list of possible completions depending on the shell you are using.
Ok, I'm done now. Go on your way. :)
Hope this helps.
Adrian