Thread: How to make a new shell

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    1

    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

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by thebiggestbang View Post
    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.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Sebastiani View Post
    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.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by thebiggestbang View Post
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    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.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by sean View Post
    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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 11:53 AM
  2. using YACC and lex to make your own shell...
    By YankeePride13 in forum Linux Programming
    Replies: 2
    Last Post: 12-28-2005, 10:00 AM
  3. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 02:16 PM
  4. How to make a simple shell?
    By ranger in forum Linux Programming
    Replies: 0
    Last Post: 03-31-2002, 03:09 AM

Tags for this Thread