When I type the following in the terminal
./a.out
what's the name of the command that I'm using? I have no idea how to look up command line options for this situation because I don't know what to actually look up.
When I type the following in the terminal
./a.out
what's the name of the command that I'm using? I have no idea how to look up command line options for this situation because I don't know what to actually look up.
The default output filename for a compiled C program is a.out. Each program parses its own arguments, so there is not canonical list of arguments. Since you have the a.out, you probably have the source code for the program. Find the function named "main" and look for code that either examines argv, or calls getopt, and maybe somebody will have provided a function (named help or usage) that displays brief program help.
Another approach would be to run the program with '-q' or '?' arguments.
Another approach would be to use 'strings' to find printable strings in the executable file,
strings a.out |less
Man pages are written separately from code, so there may not be man pages for your executable.
./
is a location, not a command. The .
represents the current directory. The /
is the directory separator. a.out
is a (presumably executable) file in the current directory. This is the default name of a compiled executable built by gcc
.
You usually use this explicit invocation method because .
is not usually part of the search path. So, if you tried to run a.out
without the ./
prefix, the system would not be able to find it even though you're in the current directory. This is a security measure (to stop you unwittingly running a malicious program when you thought you were running something else), and is a good thing.
a.out is the default name of a 'c' program that has been compile without giving it a name. Usually programs are compiled with an -ofilename parameter
The command may not have any documentation of what its options are. If it's a precompiled binary you may have very little recourse to find out what its options are, if any. You could try to strace it to find clues, but there's no guarantee the program has a manpage or any kind of --help
output.
./a.out
is by itself a command. Lets try to understand about this.
Command is basically an executable element. It can be either binary or even a shell script. In your case a.out is an executable binary element. For the command line options of a.out, please refer "argv", "argc" parameters in the main() function of the source code which is compiled and linked to get a.out.
Learn more by visiting Program Arguments
Bonus Details on Command Execution:
For a shell to execute the command, there are two well known methods.
Method 1:
Explicitly provide the path of the executable along with name of the command.
Example 1: To execute commands in present working directory by explicitly providing path:
./a.out
'.'[dot] means current directory.
Example 2: To execute commands in anywhere from anywhere by explicitly providing path
/home/username/a.out
Method 2:
Update the PATH shell environment variable to include the path of the command to be executed.
Type : env | grep -i "PATH" to know the locations currently looked over for a command to be executed if just the name of the command is provided.
If you update the PATH shell env variable to contain the location of your a.out, you can simply type:
a.out
Type below command to update the PATH shell env variable
export PATH=$PATH:/path-to-executable
You might have noticed this style.
You would have only typed "rm" and still the shell is able to execute the command. Reason is, path of command is implicit and found over reading "PATH" shell env variable.
For executing user generated commands, while Example 2 of Method 1 is sufficient in most cases, you still find the Method 2 useful at places where in you use the command extensively, day-in and day-out.