LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to make a new shell (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-make-a-new-shell-747631/)

anirvana 08-14-2009 05:30 PM

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

Tinkster 08-14-2009 07:29 PM

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

jstephens84 08-14-2009 10:39 PM

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.

anirvana 08-15-2009 08:05 PM

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.

neonsignal 08-15-2009 09:42 PM

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.

anirvana 08-15-2009 11:13 PM

@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?

anirvana 09-11-2009 06:15 PM

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?

lutusp 09-11-2009 06:29 PM

Quote:

Originally Posted by anirvana (Post 3679363)
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.


All times are GMT -5. The time now is 02:25 AM.