Re: [dev] s - suckless shell

From: <>
Date: Sat, 13 Aug 2016 11:46:41 +0100

On 2016-08-13 07:31, Ben Woolley wrote:
>> On Aug 12, 2016, at 2:41 PM, wrote:
>> Hello!
>> GNU Bash is 138227 lines of code. I wrote a simpler shell* in 800
>> lines:
>> *It is not a true POSIX shell. You can't run existing scripts with it.
>> It's technically just a command interpreter.
>> With that out the way here's an overview of how it works:
>> Tokenization [tokenizer.c]: Instead of the strange and complex way
>> that normal shells work (where "$X" is different to $X for example) s
>> works by a strict tokenize -> variable expansion -> parse -> execute
>> pipeline. This makes it much easier to program with and less likely
>> for scripts to break simply because your CWD has a space in it.
>> Variable expansion [variables.c]: The expander supports both $FOO and
>> ${FOO} syntax, it just resolves environment variables.
>> Parsing [parser.c]: There are just 3 binary operations |, && and ||
>> and '&' optional at the end of a line. There is no "if" or looping or
>> anything. parser.c is 85 lines of code and uses my region [region.c]
>> based allocator to simplify teardown of the structure when it needs to
>> be free'd.
>> [interpreter.c] The interpreter is a simple recursive process that
>> walks the AST, creating pipes and forking off children.
>> [supporting/*.c] Instead of redirection operators like <, > and >>
>> being part of the language they are simply provided as supporting
>> programs that should be added to the $PATH: < is basically just cat.
>> The redirection operators are all packaged together in busybox style.
>> Similarly glob is not part of the language, it is a 20 line script
>> instead. You use it like this: glob rm *py
>> [builtins.c] Of course a shell cannot do everything by external tools
>> - so the builtins cd, source, set, unset are provided (and treated
>> specially by the interpreter).
>> It can run scripts you supply, shebang works, using it in a terminal
>> interactively works. In theory enough for practical every day use.
>> Except for the low linecount (it is even smaller than execline) and
>> simplicity of the lexical aspect of the shell language it does not
>> have strong benefits over existing shells (especially since it is not
>> POSIX compatible) but I hope that the code may be interesting or
>> refreshing to others who are unhappy with the excess of bloat most
>> software has.
> I think it's pretty cool. There are some interesting shortcuts, like
> the redirection and glob not as built-ins, and trying to be just a
> shell and not a scripting language. It also seems to have a consistent
> ideology behind it, in a good sense.

Thanks Ben!

That's true, consistent ideology was the main thing I was going for.

We've seen a lot of high profile dangers like shellshock and the steam
software deleting your home directory come from the bad design of early
shell languages. This is why I made s have such a rigid and minimal
Received on Sat Aug 13 2016 - 12:46:41 CEST

This archive was generated by hypermail 2.3.0 : Sat Aug 13 2016 - 12:48:12 CEST