A Scheme Shell

Although robust enough for general use, adventures into the esoteric periphery of the C shell may reveal unexpected quirks. -- SunOS 4.1 csh(1) man page, 10/2/89

# Prologue

Shell programming terrifies me. There is something about writing a simple shell script that is just much, much more unpleasant than writing a simple C program, or a simple COMMON LISP program, or a simple Mips assembler program. Is it trying to remember what the rules are for all the different quotes? Is it having to look up the multi-phased interaction between filename expansion, shell variables, quotation, backslashes and alias expansion? Maybe it's having to subsequently look up which of the twenty or thirty flags I need for my grep, sed, and awk invocations. Maybe it just gets on my nerves that I have to run two complete programs simply to count the number of files in a directory (`ls | wc -l`), which seems like several orders of magnitude more cycles than was really needed.

Whatever it is, it's an object lesson in angst. Furthermore, during late-night conversations with office mates and graduate students, I have formed the impression that I am not alone. In late February1, I got embroiled in a multi-way email flamefest about just exactly what it was about Unix that drove me nuts. In the midst of the debate, I did a rash thing. I claimed that it would be easy and so much nicer to do shell programming from Scheme. Some functions to interface to the OS and a few straightforward macros would suffice to remove the spectre of `#!/bin/csh` from my life forever. The serious Unix-philes in the debate expressed their doubts. So I decided to go do it.

Probably only take a week or two.

Keywords: operating systems, programming languages, Scheme, Unix, shells, functional languages, systems programming.

1 February 1992, that is.