Home

Shell, Awk, and Make Should Be Combined

2016-11-13

The shell has been a part of Unix since its first release in 1971, while Awk and Make were additions to Unix, both released in 1977 and developed at Bell Labs.

These three tools were conceived as domain-specific languages with distinct roles:

Not only do they survive four decades later, they're as popular as ever:

The success of these tools has led to an common anti-pattern: they grew into ALGOL-like languages with a quirky syntax constrained by backward compatibility.

Tomorrow, I'll show this with example code in three languages. For now, let me support this argument with some observations:

Quoting is difficult when composing two languages, let alone three. Here's a sample from my ~/src dir:

$ grep AWK */Makefile
busybox-1.24.2/Makefile:        ($(OBJDUMP) -h $< | $(AWK) '/^ +[0-9]/{print $$4 " 0 " $$2}'; $(NM) $<) | sort > $@
cityhash-1.1.1/Makefile:  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
dash-0.5.8/Makefile:      $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
glibc-2.23/Makefile:    AWK='$(AWK)' scripts/check-local-headers.sh \
re2c-0.16/Makefile:  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \

As far as awk:

What all three languages have in common:

Conclusion

Despite their origins, the three languages are now more similar than different — at least semantically. We'll see tomorrow that their syntaxes are wildly and needlessly different.

And while I'm wary of discussing plans without code, I should say that I want oil to subsume awk and make as well. I expect that this theme will consume many more blog posts.