Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can a make a command shell?

0 views
Skip to first unread message

coolboy

unread,
Jul 18, 2001, 9:21:34 PM7/18/01
to
I want to make a command shell such as bash,how to do it and where can I
find a model or principium?


Bill Marcum

unread,
Jul 19, 2001, 10:56:58 AM7/19/01
to

coolboy wrote in message <9j5cnm$m...@nntpb.cb.lucent.com>...

>I want to make a command shell such as bash,how to do it and where can I
>find a model or principium?
>
You can find the source code of bash and probably some others at
www.gnu.org. There's also a shell written as a one line C program which
I've seen in some people's signatures. I think this was written for
the Obfuscated C contest, so try running a search engine on that.


brian hiles

unread,
Jul 19, 2001, 2:50:39 PM7/19/01
to

I've posted this many times; a search of this newsgroup of ("shell" and
("source" or "code")) would have "netted" you this as quick. Here it is:

#define D ,close(
char*c,q[512],m[256],*v[99],**u,*i[3];int f[2],p;main(){for(m[m[60]=m[62]=
32]=m[*m=124[m]=9]=6;e(-8),gets(1+(c=q))||exit(0);r(0,0))for(;*++c;);}
r(t,o){*i=i[2]=0;for(u=v+98;m[*--c]^9;m[*c]&32?i[*c&2]=
*u,u-v^98&&++u:3)if(!m[*c]){for(*++c=0;!m[*--c];);*--u=
++c;}u-v^98?strcmp(*u,"cd")?*c?pipe(f),o=f[1]:1,(p=fork())?e(p),o?
r(o,0)D o)D*f):4,wait(0):(o?dup2(*f,0)D*f)D o):*i?1 D
0),e(open(*i,0)):5,t?dup2(t,1)D t):i[2]?9 D
1),e(creat(i[2],438)):2,e(execvp(*u,u))):e(chdir(u[1])*2):6;}
e(x){x<0?write(2,"?\n$ "-x/4,2),x+1||exit(1):5;}

It is really quite remarkable just how much functionality the above
implements in so little code (and they say that C is terse -- I
would say that C is "trs" indeed!)

Also see: http://shelldorado.com/newsletter/issues/1999-1-Feb.html

I am engaged in writing a paper on coding shells, including the
DLable resources, in graduated steps of sophistication, with
references to the canonical whitepapers on the usual subsystems in
modern shells (like job control, history, command re-editting,
etcetera.)

=Brian

0 new messages