LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-14-2009, 05:30 PM   #1
anirvana
Member
 
Registered: Mar 2007
Posts: 30

Rep: Reputation: 15
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
 
Old 08-14-2009, 07:29 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
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
 
Old 08-14-2009, 10:39 PM   #3
jstephens84
Senior Member
 
Registered: Sep 2004
Distribution: (Home)Opensolaris, Ubuntu, CentOS, (Work - AIX, HP-UX, Red Hat)
Posts: 2,054

Rep: Reputation: 83
Not sure how helpful this is but I would start by finding which .c file has the line
Code:
int main()
{
 // some code here
}
that should be a great starting point and actually the entry point for the application.
 
Old 08-15-2009, 08:05 PM   #4
anirvana
Member
 
Registered: Mar 2007
Posts: 30

Original Poster
Rep: Reputation: 15
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)
Versus

Code:
main()
in some other files.

@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.
 
Old 08-15-2009, 09:42 PM   #5
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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.
 
Old 08-15-2009, 11:13 PM   #6
anirvana
Member
 
Registered: Mar 2007
Posts: 30

Original Poster
Rep: Reputation: 15
@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?
 
Old 09-11-2009, 06:15 PM   #7
anirvana
Member
 
Registered: Mar 2007
Posts: 30

Original Poster
Rep: Reputation: 15
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");}
in execute_cmd.c in the latest bash-4.0 code right before it uses the COMMAND_NOT_FOUND hook. Before hookf = find_function (NOTFOUND_HOOK); approx line # 4451

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
aiiiiiiii
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: [: too many arguments
-bash: complete: aiiiiiiii: no completion specification
bogus@mycomp:~$ ls /ho
malloc: /Users/chet/src/bash/src/parse.y:5561: assertion botched
free: called with unallocated block argument
last command: (null)
Aborting...Connection to 127.0.0.1 closed.
I looked up the error code and it matches with an entry for a bash bug
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?

Last edited by anirvana; 09-11-2009 at 09:06 PM. Reason: missplet Hello as Hell
 
Old 09-11-2009, 06:29 PM   #8
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by anirvana View Post
Hell 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.

[ snip ]

I looked up the error code and it matches with an entry for a bash bug
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?
A few. This is not how one learns how to write computer programs.

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.
 
  


Reply

Tags
bash, code, input, shell


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make GUI for shell script ? Joydeep Bakshi Linux - Software 3 11-07-2007 01:43 AM
Using shell aliases in make Dark_Helmet Programming 13 02-26-2007 03:16 AM
How to Make CSH the default shell intels_ss Linux - Newbie 5 07-21-2005 03:22 PM
'make' & 'make install commands not recognised by shell gilbertt Linux - Software 4 05-04-2004 08:04 AM
shell scripting, how to make many Introx Linux - Newbie 2 04-09-2004 05:06 PM


All times are GMT -5. The time now is 11:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration