gaf
User
 Platinum Osdever
| Posts: 153 |  | Karma: 10
|
Re:shell - 2006/07/17 10:42
Now I would like to know what exacly is shell (I know that it is command line) but I wanted to know what it is in details... A shell is a program (sometimes also a module of the kernel) that reads in the user's commands and executes them. It can thus be seen as kind of a middleware that allows the user to interact with the system. Most of the commands that can be run in are shell are not handled internally, but are rather passed-on to utility programms that then do the actual work. Todays shells are often very complex systems featuring a rich syntax that also allows for shell-scripts.
I think the introduction paragraph of the bash manual also summarizes it quite well (link).
And how to write my own shell (I do not need as for now any filesystem, I just wanted to write shell which could use some commands like "reset","info","clearscreen" You'll first of all need a simple set of functions that allow you to get input from the keyboard. At the very least you should write a procedure that allows you to check if any key has been pressed, and one that can be used to get the pressed key (char PeekKey(), char GetKey()). Both of them just check a small buffer that gets filled by the interrupt-handler when a key gets pressed. On top of these two functions you can then add a procedure that reads in a whole line by calling GetKey() until a "enter" is detected (or a maximum length is exceeded).
The read-in line then has to get parsed in order to extract command name and arguments. You can use Solar's C library (link, public domain) to do this in a standard compliant way.
Once you have extracted the command, all you have to do is to call the procedure linked to it. For the moment you can do this using a simple switch - a more advanced approach (that can also be used with filesystems) would be to use a table of function-pointers.
regards, gaf
|