Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

Smallest Unix Shell


Article: 8651 of alt.hackers
From: wkt@dolphin.cs.adfa.oz.au (Warren Toomey)
Newsgroups: alt.hackers
Subject: Smallest Unix Shell
Date: 21 Sep 1995 00:00:52 GMT
Organization: Australian Defence Force Academy
Lines: 26
Approved: s.claus@north.pole.com
Distribution: world
Message-ID: 43q9vk$rso@euryale.cc.adfa.oz.au
NNTP-Posting-Host: 131.236.20.5
Status: RO

ObHack: A challenge with a friend to come up with the smallest Unix shell in C.
Here's the results, the smallest being 123 characters (124 with a \n):

char*c,b[99],*v[99],i;main(){while(putchar('>')&&gets(b)){for(c=b,i=0;v[i++]=
strtok(c," ");c=0);(fork()||execvp(*v,v))&&wait(0);}}

char*c,b[99],*v[99],i;main(){while(putchar(62),gets(b)){for(c=b,i=0;v[i++]=
strtok(c," ");c=0);fork()?wait(0):execvp(*v,v);}}

char*c,b[99],*v[99],i;main(){while(putchar(62),gets(b)){for(c=b,i=0;v[i++]=
strsep(&c," "););fork()?wait(0):execvp(*v,v);}}

char*c,b[99],*v[99],**w;main(){while(putchar(62),gets(b)){for(c=b,w=v;*w++=
strsep(&c," "););fork()?wait(0):execvp(*v,v);}}

I've broken them into 2 lines each for easier reading. Fixing the small bug
that all four versions have would increase the size by at least 10 characters.

	Warren

--

Copyright (c) 1995, Warren Toomey. Microsoft Network is prohibited from
redistributing this work in any form, in whole or in part, without a license.
License to distribute this post is available to Microsoft for $1000.
Posting without permission constitutes an agreement to these terms.



Child Child Child Child

Back to index