bs (programming language)
bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems.[1] It provides both an interactive prompt and accepts a file containing a program, e.g., loaded using the Shebang (Unix) #!/usr/bin/bs.
An early man page states bs "is a remote descendant of Basic (sic) and SNOBOL4, with a little C (programming language) thrown in."[1]
History
The bs command appears in UNIX System III Release 3.0 (1980), first released outside of Bell Labs in 1982.[1] The Release 3.0 manual mentions it prominently, on page 9, as follows (emphasis added)[2]:
Writing a program. To enter the text of a source program into a UNIX file, use ed(1). The four principal languages available under UNIX are C (see cc(1)), Fortran (see f77(1)), bs (a compiler/interpreter in the spirit of Basic, see bs(1)), and assembly language (see as(1)).
Its origin is not recorded in the manual, however the bs command was present in UNIX/TS 1.0 (November 1978)[3], PWB/UNIX 2.0 (June 1979)[3], and CB UNIX editions 2.1 (November 1979)[4][5] and 2.3 (1981)[6]. The bs command does not appear in the UNIX Support Group’s March 1977 release[3], nor a PWB/UNIX manual dated May, 1977[7], nor any version of Research Unix, e.g., 7th edition (1979) nor 10th edition (final, 1989), nor does it appear in the Berkeley Software Distribution, e.g., 4.2 (1983), suggesting those are not candidate origins.
Subsequently and into the 1990s, bs was included in a variety of System III-derived or System V-derived commercial operating systems including, but not limited to: PC/IX[8]; UNIX System V Releases 2 & 3: SVR2[9], SVR3, SVR3.2 (1986)[10]; HP-UX[11]; AIX[12]; and A/UX[13]. (The User's Manual for the AT&T Unix PC (3B1) specifically mentions that the bs command is not available, but that it is available on SVR3.2.[9])
Occasionally, bs was touted as one of the primary programming languages for development under UNIX.[2][8][14] However, bs is not included in the POSIX.1 commands and utilities (the standard List of Unix commands) nor in the Single UNIX Specification and is not provided with most contemporary operating systems. For example in Linux, similar syntax and functionality is provided by bc (programming language), Perl, and POSIX shell.
In the 21st century, bs is present in, at least, HP-UX Release 11i (2000)[11], as well as AIX versions 6.1 (2007)[12] and 7.2 (2018)[15], likely due to their UNIX System V heritage.
Design and Features
The bs man page, ostensibly the language's only specification, characterizes it as follows: "The language is designed for programming tasks where program development time is as important as the resulting speed of execution. The language minimizes the formalities of data declaration and file manipulation. Line-at-a-time debugging, the trace and dump keywords, and useful run-time error messages simplify program testing. Furthermore, you can debug incomplete programs, test inner functions before outer functions have been written, and test outer functions before inner functions have been written."[16]
The bs language shares some features and syntax with BASIC, SNOBOL, and the C Programming Language, the two former presumably inspiring its name. Like BASIC, it can be used interactively, either executing statements immediately or collecting them into a program to be executed subsequently. Like SNOBOL4, the assignment operator ("=") is used for I/O and it can execute code in strings using its eval function. The built-in format function, limited to one argument, supports a subset of C's printf format conversion specifiers, e.g., "%f".
The language has some conspicuous elements. For instance, its program functions are defined using the fun ... nuf syntax and these can have local variables. Also, bs can operate in two modes, either interpreting (and executing) statements and programs or compiling them, and switching between the two using compile and stop. Otherwise, its functionality is unique only collectively (in one language), since individual features are redundant with those of coexisting tools, such as the Unix Shell, e.g., file I/O and loops, and AWK, e.g., associative arrays and Regular expression matching.
The bs language was meant for convenient development and debugging of small, modular programs. It has a collection of syntax and features from prior, popular languages and can be compiled for better performance, unlike a Shell script. As such, in purpose and function, bs is a modest predecessor of Perl and Python (programming language), albeit a largely unknown one.
Syntax Examples
The following examples are derived from an A/UX bs(1) man page.[17]
This example uses bs as a calculator:
$ bs # Distance (inches) light travels in a nanosecond. 186000 * 5280 * 12 / 1e9 11.78496 ... # Compound interest # (6% for 5 years on $1,000). int = .06 / 4 bal = 1000 for i = 1 5*4 bal = bal + bal*int bal - 1000 346.855007 ... exit
This example is the outline of a typical bs program:
# initialize things: var1 = 1 open("read", "infile", "r") ... # compute: while ?(str = read) ... next # clean up: close("read") ... # last statement executed (exit or stop): exit # last input line: run
This example demonstrates I/O:
# Copy "oldfile" to "newfile". open("read", "oldfile", "r") open("write", "newfile", "w") ... while ?(write = read) ... # close "read" and "write": close("read") close("write") # Pipe between commands. open("ls", "!ls *", "r") open("pr", "!pr -2 -h ’List’", "w") while ?(pr = ls) ... ... # be sure to close (wait for) these: close("ls") close("pr")
Sample Program
The following is a sample bs program that emits the words to the song 99 Bottles of Beer using /usr/bin/bs (1996).[18]
fun sing(n, end) s s = ("s", "")[ match(n, "^1$") ] put = format(format(format("%s bottle%%s of beer%%%%s", n), s), end) nuf for n = 99, n, put = "" sing(format("%-0.0f", n), " on the wall,") sing(format("%-0.0f", n), ",") put = "take one down, pass it around," --n sing((format("%-0.0f", n), "no")[ 0 == n ], " on the wall.") next
References
- ^ a b c UNIX User's Manual (Release 3.0 ed.). Bell Telephone Laboratories, Incorporated. 1980. p. 95.
- ^ a b UNIX User's Manual (PDF) (Release 3.0 ed.). Bell Telephone Laboratories, Incorporated. 1980. p. 9.
- ^ a b c Personal conversation with John R. Mashey, 9 September 2019.
- ^ https://www.tuhs.org/Archive/Distributions/USDL/CB_Unix/cbunix_man7.pdf
- ^ https://www.tuhs.org/Archive/Distributions/USDL/CB_Unix/cbunix_man1_01.pdf
- ^ J. D. Doan, ed. (May 1981). CB-UNIX Programmer's Manual, Edition 2.3 (PDF). Columbus, OH: Bell Telephone Laboratories. p. iii.
- ^ T. A. Dolotta; R. C. Haight; E. M. Piskorik, eds. (May 1977). "Section 1". PWB UNIX Programmer's Manual, Edition 1. Piscataway, New Jersey: Bell Telephone Laboratories.
- ^ a b "IBM Goes UNIX". PC Magazine. June 12, 1984. p. 218.
- ^ a b "Volume 1". AT&T UNIX PC UNIX System V User's Manual (PDF). AT&T. 1986. p. 8.
- ^ "Volume 1 Commands and Utilities". UNIX Programmer's Manual (PDF). AT&T. 1986. p. 41.
- ^ a b "Section 1 (A-M)". HP-UX Reference Release 11i User Commands (PDF) (1 ed.). Hewlett-Packard Company. 2000. p. 93.
- ^ a b "Section 1 (a-c)". AIX Version 6.1 Commands Reference (PDF) (First ed.). International Business Machines Corporation. 2007. p. 251.
- ^ "Section 1 (A-L)". A/UX Command Reference (PDF) (2.0 ed.). Apple Computer, Inc. 1990. p. 93.
- ^ "A/UX: Development Tools", Apple, Inc, 18 February 2012. Retrieved on 9 September 2019.
- ^ "Section 1 (a-c)". AIX Version 7.2 Commands Reference. IBM Corporation. 2018. p. 282.
- ^ The /usr/catman/u_man/man1/bs.1.Z file, A/UX 3.0.1 installation media, Apple Inc. (1993)
- ^ The /FILES file, A/UX 3.0.1 installation media, Apple Inc. (1993)
- ^ http://www.99-bottles-of-beer.net/language-bs-103.html