C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-14-2009, 04:46 PM   #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
thebiggestbang is offline   Reply With Quote
Old 08-14-2009, 05:25 PM   #2
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 4,923
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.
Sebastiani is offline   Reply With Quote
Old 08-14-2009, 05:49 PM   #3
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
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.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 08-15-2009, 08:43 AM   #4
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
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.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Old 08-15-2009, 10:15 AM   #5
Super Moderator
 
Join Date: Sep 2001
Posts: 4,680
Quote:
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.
sean is offline   Reply With Quote
Old 08-15-2009, 10:45 AM   #6
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
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.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is offline   Reply With Quote
Reply

Tags
bash, c programming, shell

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:59 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22