PDA

View Full Version : How to make a new shell



thebiggestbang
08-14-2009, 04:46 PM
Hello everyone,
I've been bitten by a linux bug and now want to develop a new shell of mine. I think I will modify the bash shell to begin with and learn how stuff works.

If someone can give me some pointers about how to take the first few steps, it would be great.

1) I have downloaded the bash 4, source code. Things look a little daunting, I am not an uber lex/yacc/C hacker.

2) I want to develop a shell/modify the bash shell, such that I can specify a command/input that must be typed in the shell for it to start working.

an example: say I made a shell called mystupidshell, and configured my system such that whenever someone logs in, thats the default shell. I want them to type in their name at the prompt first and then type in the commands they want to use like ls, cd.. if they don't type in their name and instead type in ls etc.. they should be shown a msg saying whats your name nd then move on to let them type in various commands.

To do this where can I start in the bash code to analyze and make changes. Should I look at shell.c?

Any pointers are greatly appreciated.
Thanks

Sebastiani
08-14-2009, 05:25 PM
Hello everyone,
I've been bitten by a linux bug and now want to develop a new shell of mine. I think I will modify the bash shell to begin with and learn how stuff works.

If someone can give me some pointers about how to take the first few steps, it would be great.

1) I have downloaded the bash 4, source code. Things look a little daunting, I am not an uber lex/yacc/C hacker.

2) I want to develop a shell/modify the bash shell, such that I can specify a command/input that must be typed in the shell for it to start working.

an example: say I made a shell called mystupidshell, and configured my system such that whenever someone logs in, thats the default shell. I want them to type in their name at the prompt first and then type in the commands they want to use like ls, cd.. if they don't type in their name and instead type in ls etc.. they should be shown a msg saying whats your name nd then move on to let them type in various commands.

To do this where can I start in the bash code to analyze and make changes. Should I look at shell.c?

Any pointers are greatly appreciated.
Thanks

If you're going to modify existing code, it's imperative that you work through the entire body of code at least once or twice until you understand the mechanics of it. Otherwise, you're just asking for trouble, and much more likely to break something along the way, as well. After you're fairly comfortable with the code base, you'll be able to move forward in confidence - not merely grasping in the dark for something that "seems to work". That said, I don't personally know much about the specifics of Linux shell designs, and so I apologize that the only advice I have for you is strictly practical. :p

brewbuck
08-14-2009, 05:49 PM
If you're going to modify existing code, it's imperative that you work through the entire body of code at least once or twice until you understand the mechanics of it.

I agree in principle, but something as complex as bash would take quite a while to completely "get." Reading through the code helps -- but don't feel bad if you don't understand everything.

MK27
08-15-2009, 08:43 AM
1) I have downloaded the bash 4, source code. Things look a little daunting, I am not an uber lex/yacc/C hacker.


Keep in mind that lex produces C source from an input file (ie, some of the source is autogenerated by lex). The input file, which contains a description of the scripting language used by the shell, is not part of the source because it is not needed to build it. You could also write someone at GNU and ask them for it.

sean
08-15-2009, 10:15 AM
To do this where can I start in the bash code to analyze and make changes. Should I look at shell.c?

Look for the main function - since you want to add functionality to the beginning of execution. I'm sure there'll be a ton of setup / init code, but it shouldn't be too far from the beginning. Also - lots of popular FOSS projects have documentation available that may decribe the purposes of different part of the source tree.

If this is the first open-source project you've looked at, don't be initimdated. Any decent project will have lots of code, but a lot of that is to deal with special cases, ensure stability, small features, etc... The basic logic is probably quite simply once you can look past all that. It just takes some experience.

However, if you're wanting to write a shell, you might want to learn about spawning process, interprocess communication, and ncurses. That's really all a shell is going to do - and if you understand that, understanding bash is just a matter of time.

MK27
08-15-2009, 10:45 AM
However, if you're wanting to write a shell, you might want to learn about spawning process, interprocess communication, and ncurses.

Bash doesn't use ncurses except on the QNX platform. It does use readline, for the command history, etc.