How to make a new shell
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 |
No idea, but I can already tell you that your shell
won't be very popular. What's the objective behind this? If you don't want people to use the machine, just don't give them access ;D Cheers, Tink |
Not sure how helpful this is but I would start by finding which .c file has the line
Code:
int main() |
Thanks for the comments guys,
@jstephens There are >1 files with main() in them ./aclocal.m4 ./array.c ./CHANGES ./configure ./configure.in ./execute_cmd.c ./input.c ./locale.c ./mksyntax.c ./shell.c input.c and shell.c seem more like the files I shold concentrate on, they have Code:
int main (argc, argv) Code:
main() @tinkster This is a small personal project to learn about the shell, I do not see it as becoming widely adopted at all. An pointers guys? Thanks. |
You might find the bash source takes a bit of working through.
If you just want to write an experimental interactive shell, have a look around for a very simple shell (eg this one), and build on that. On the other hand, if you want to learn in detail about how the different facilities in bash work, then by all means dive into the source code. |
@neonsignal
Thanks for the link, I will definitely look it up. You are on the money about bash code needs a little getting used to .. especially for newbies like me. I was wondering if there is a forum more dedicated for bash specific issues, I did try searching groups.google.com for "bash code" etc.., but I got answers all over the place. Even though I will take a look at the simpleCshell, I would like to stick to hammering it out with bash. It'll be painful I think but I expect I'll learn a lot. Thanks again everyone, and any starter tips would be greatly appreciated. Just to restate: I want that when the shell is spawned, the user will enter his/her name and then continue normal operation. Where could I concentrate to plug in my code to accept input and throw operation into normal mode. Also, another wild thought: is it feasible to somehow spawn a vanilla bash shell, somehow pipe (I know its not the right word) the output to my "name-accepting" program and then throw the user back to the vanilla bash? |
Hello helpful people,
Can someone please provide me with an idea regarding why my 2 lines inserted into main bash code seem to produce an error msg. My goal is to intercept the command typed and to write it out to a buffer file for further processing and hand control back to standard bash execution. I inserted Code:
if (command != 0) {printf("aiiiiiiii\n");} I set up a test user on my system, changed the default shell to newly compiled shiny shell and logged in only to get Code:
aiiiiiiii http://osdir.com/ml/bug-bash-gnu/2009-04/msg00132.html and it seems there is a patch for the bug.. but I just inserted 2 lines of code in there. I don't profess to be a C guru, but there's little scope for error in the 2 lines of code! any suggestions? |
Quote:
1. Start small. Write your own command shell and test it. Make sure it works. 2. Add more sophisticated operations to your shell. Test them. 3. Never move ahead if anything happened that you didn't understand. Instead, analyze the operation of your program -- why it succeeded as well as why it failed. I have to say that hacking the source for Bash, adding lines and discovering it won't compile but not understanding why, is the least productive imaginable way to learn computer programming. |
All times are GMT -5. The time now is 02:25 AM. |