Bash command Implementation
Hi all,
Bash commands have been outlined to me as follows: Command Options Arguments My question is, how is this implemented in the source code? Is a command a function that is called for example? Or is it done some other way? Any examples to hand? Thanks in advance for any help! I am simply trying to understand better the mechanics of what happens when I type a command. |
Quote:
These 2 links might shed some light: - The Bash Parser - (POSIX) Shell Command Line Processing Outline Very simple example: Code:
FOO="/tmp" |
thanks druuna - I didn't even know there was a bash parser :) - don't tell anyone!!! ;)
|
Quote:
Having a good knowledge of these parsing rules makes CLI life much easier and explains certain behaviour. Quote:
|
Quote:
Technically, all applications receive two items of information at the main program initiation (as in the following code) Code:
#include <stido.h> /*standard I/O library*/ As illustrated, how the parameters are used is up to the program. By convention (in other words, historical), program options are identified by strings that start with a '-' character. Some applications DON'T follow this convention - one notable one is the dd utility (data dump originally) The dd utility interprets all the parameters as a "name=value" list, so the program itself does that. Other programs (more conventional) use a library function "getopt" which will do most of the work, and allow the program to use a simple switch code block to interpret the options. Still other programs will mix options and parameters - using things like -f for the option, which indicates the following parameter is a file. In the basic form this is also handled by the getopt library, any options remaining after it has finished evaluation have to handled manually (though they could just be ignored, a perfectly valid thing to do). |
All times are GMT -5. The time now is 10:21 PM. |