Bs (programming language)

Last updated
bs
Designed by Richard C. Haight
First appeared1980;41 years ago (1980)
OS Unix
Influenced by
BASIC, SNOBOL4, C

bs is a programming language and a compiler/interpreter for modest-sized programs on UNIX systems. [1] The bs command can be invoked either for interactive programming or with a file containing a program, optionally taking arguments, via a Unix shell, e.g., using a Shebang (Unix) #!/usr/bin/bs.

Contents

An early man page states, "[bs] is a remote descendant of Basic [sic] and SNOBOL4, with a little C 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] It was written by Dick Haight (Richard C. Haight) circa 1978, who recounts it as follows: [2]

I wrote bs at the time Unix (V 3?) and all of the commands were being converted from assembler to C. So [ Ken Thompson’s ] bas became my bs — sort of.

The Release 3.0 manual mentions bs prominently on page 9 (emphasis added): [3]

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)).

While not released outside prior to System III, the bs command was present internally in UNIX/TS 1.0 (November 1978), [4] PWB/UNIX 2.0 (June 1979), [4] and CB UNIX editions 2.1 (November 1979) [5] [6] and 2.3 (1981). [7] The bs command does not appear in some earlier internal releases, e.g., the UNIX Support Group’s March 1977 release, [4] nor the PWB/UNIX manual dated May, 1977, [8] suggesting its creation circa 1978. It does not appear in any version of Research Unix nor the Berkeley Software Distribution.

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; [9] UNIX System V Releases 2 & 3: SVR2, [10] SVR3, SVR3.2 (1986); [11] HP-UX; [12] AIX; [13] and A/UX. [14] (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. [10] )

Occasionally, bs was touted as one of the primary programming languages for development under UNIX. [3] [9] [15] 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, Perl, and POSIX shell.

In the 21st century, bs is present in, at least, HP-UX Release 11i (2000), [12] as well as AIX versions 6.1 (2007) [13] and 7.2 (2018), [16] likely due to their UNIX System V heritage.

Design and features

The bs [1] man page, ostensibly the programming language's only specification, characterizes it as follows:

Bs is designed for programming tasks where program development time is as important as the resulting speed of execution. Formalities of data declaration and file/process manipulation are minimized. Line-at-a-time debugging, the trace and dump statements, and useful run-time error messages all simplify program testing. Furthermore, incomplete programs can be debugged; inner functions can be tested before outer functions have been written and vice versa.

A bs program is compiled and executed differently from programs written in the other principal Unix programming languages of the time: C, FORTRAN, and assembly language, whose respective commands compile program source code to executable assembler output (a.out). Instead, a bs program is, first, converted by the bs command to an internal reverse Polish (RPN) intermediate representation and then executed by the command's internal virtual stack machine. [17] The bs language, thus, is a hybrid interpreter and compiler and a divergence in Unix programming from Ancient Unix.

The bs language shares some features and syntax with BASIC, SNOBOL, and C, 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 in SNOBOL4, the assignment operator (=) is used for I/O and bs can execute code in strings, using its eval function. It also includes SNOBOL's interrogation operator (?) used to test whether an expression evaluation succeeds or not. 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 its functions 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 but it is internally compiled, unlike a Shell script. As such, in purpose, design, and function, bs is a largely unknown, modest predecessor of hybrid interpreted/compiled languages such as Perl and Python.

Syntax Examples

The following examples are derived from an A/UX bs(1) man page. [18]

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 / 4bal=1000fori=15*4 bal= bal + bal*int  bal - 1000346.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. [19]

funsing(n,end)ss=("s","")[match(n,"^1$")]put=format(format(format("%s bottle%%s of beer%%%%s",n),s),end)nufforn=99,n,put=""sing(format("%-0.0f",n)," on the wall,")sing(format("%-0.0f",n),",")put="take one down, pass it around,"--nsing((format("%-0.0f",n),"no")[0==n]," on the wall.")next

See also

Related Research Articles

AWK (awk) is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.

Shell script Script written for the shell, or command line interpreter, of an operating system

A shell script is a computer program designed to be run by the Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text. A script which sets up the environment, runs the program, and does any necessary cleanup, logging, etc. is called a wrapper.

The Single UNIX Specification (SUS) is the collective name of a family of standards for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group. If an operating system is submitted to The Open Group for certification, and passes conformance tests, then it is deemed to be compliant with a UNIX standard such as UNIX 98 or UNIX 03.

In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions of file system objects sometimes known as modes. It is also used to change special mode flags such as setuid and setgid flags and a 'sticky' bit. The request is filtered by the umask. The name is an abbreviation of change mode. They are shown when listing files in long format.

Man page Unix software documentation

A man page is a form of software documentation usually found on a Unix or Unix-like operating system. Topics covered include computer programs, formal standards and conventions, and even abstract concepts. A user may invoke a man page by issuing the man command.

Bourne shell Command-line interpreter for operating systems

The Bourne shell (sh) is a shell command-line interpreter for computer operating systems.

ls

In computing, ls is a command to list computer files in Unix and Unix-like operating systems. ls is specified by POSIX and the Single UNIX Specification. When invoked without any arguments, ls lists the files in the current working directory. The command is also available in the EFI shell. In other environments, such as DOS, OS/2, and Microsoft Windows, similar functionality is provided by the dir command. The numerical computing environments MATLAB and GNU Octave include an ls function with similar functionality.

In software development, Make is a build automation tool that automatically builds executable programs and libraries from source code by reading files called Makefiles which specify how to derive the target program. Though integrated development environments and language-specific compiler features can also be used to manage a build process, Make remains widely used, especially in Unix and Unix-like operating systems.

A/UX Early Unix-based operating system from Apple Computer

A/UX is Apple Computer's implementation of the Unix operating system for Macintosh computers, integrated with System 7's graphical interface and application compatibility. Launched in 1988 and discontinued in 1995 with version 3.1.1, it is Apple's first official Unix-based operating system. A/UX requires select models of 68k-based Macintosh with an FPU and a paged memory management unit (PMMU), including the Macintosh II, SE/30, Quadra, and Centris series. It was never the predecessor to macOS, a variant of UNIX currently bundled with Apple's desktop computers.

The Common Object File Format (COFF) is a format for executable, object code, and shared library computer files used on Unix systems. It was introduced in Unix System V, replaced the previously used a.out format, and formed the basis for extended specifications such as XCOFF and ECOFF, before being largely replaced by ELF, introduced with SVR4. COFF and its variants continue to be used on some Unix-like systems, on Microsoft Windows, in UEFI environments and in some embedded development systems.

dd is a command-line utility for Unix and Unix-like operating systems, the primary purpose of which is to convert and copy files.

UNIX System V early commercial UNIX operating system

Unix System V is one of the first commercial versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V were released, numbered 1, 2, 3, and 4. System V Release 4 (SVR4) was commercially the most successful version, being the result of an effort, marketed as Unix System Unification, which solicited the collaboration of the major Unix vendors. It was the source of several common commercial Unix features. System V is sometimes abbreviated to SysV.

In some programming languages, eval, short for the English evaluate, is a function which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval. The input to eval is not necessarily a string; it may be structured representation of code, such as an abstract syntax tree, or of special type such as code. The analog for a statement is exec, which executes a string as if it were a statement; in some languages, such as Python, both are present, while in other languages only one of either eval or exec is.

In computing, umask is a command that determines the settings of a mask that controls how file permissions are set for newly created files. It may also affect how the file permissions are changed explicitly. umask is also a function that sets the mask, or it may refer to the mask itself, which is formally known as the file mode creation mask. The mask is a grouping of bits, each of which restricts how its corresponding permission is set for newly created files. The bits in the mask may be changed by invoking the umask command.

The Programmer's Workbench (PWB/UNIX) is an early, now discontinued, version of the Unix operating system that had been created in the Bell Labs Computer Science Research Group of AT&T. Its stated goal was to provide a time-sharing working environment for large groups of programmers, writing software for larger batch processing computers.

Source Code Control System (SCCS) is a version control system designed to track changes in source code and other text files during the development of a piece of software. This allows the user to retrieve any of the previous versions of the original source code and the changes which are stored. It was originally developed at Bell Labs beginning in late 1972 by Marc Rochkind for an IBM System/370 computer running OS/360.

The PWB shell was a Unix shell.

In computing, a dynamic linker is the part of an operating system that loads and links the shared libraries needed by an executable when it is executed, by copying the content of libraries from persistent storage to RAM, filling jump tables and relocating pointers. The specific operating system and executable format determine how the dynamic linker functions and how it is implemented.

chsh is a command on Unix-like operating systems that is used to change a login shell. Users can either supply the pathname of the shell that they wish to change to on the command line, or supply no arguments, in which case chsh allows the user to change the shell interactively.

Unix Family of computer operating systems that derive from the original AT&T Unix

Unix is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in the 1970s at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

References

  1. 1 2 3 4 UNIX User's Manual (Release 3.0 ed.). Bell Telephone Laboratories, Incorporated. 1980. p. 95.
  2. Personal communication from Dick Haight, 10 September 2019.
  3. 1 2 UNIX User's Manual (PDF) (Release 3.0 ed.). Bell Telephone Laboratories, Incorporated. 1980. p. 9.
  4. 1 2 3 Personal conversation with John R. Mashey, 9 September 2019.
  5. "CB/UNIX man 7", The Unix Heritage Society , November 1979. Retrieved on 9 September 2019.
  6. "CB/UNIX man 1", The Unix Heritage Society , November 1979. Retrieved on 9 September 2019.
  7. J. D. Doan, ed. (May 1981). CB-UNIX Programmer's Manual, Edition 2.3 (PDF). Columbus, OH: Bell Telephone Laboratories. p. iii.
  8. 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.
  9. 1 2 "IBM Goes UNIX". PC Magazine. June 12, 1984. p. 218.
  10. 1 2 "Volume 1". AT&T UNIX PC UNIX System V User's Manual (PDF). AT&T. 1986. p. 8.
  11. "Volume 1 Commands and Utilities". UNIX Programmer's Manual (PDF). AT&T. 1986. p. 41.
  12. 1 2 "Section 1 (A-M)". HP-UX Reference Release 11i User Commands (PDF) (1 ed.). Hewlett-Packard Company. 2000. p. 93.
  13. 1 2 "Section 1 (a-c)". AIX Version 6.1 Commands Reference (PDF) (First ed.). International Business Machines Corporation. 2007. p. 251.
  14. "Section 1 (A-L)". A/UX Command Reference (PDF) (2.0 ed.). Apple Computer, Inc. 1990. p. 93.
  15. "A/UX: Development Tools", Apple, Inc , 18 February 2012. Retrieved on 9 September 2019.
  16. "Section 1 (a-c)". AIX Version 7.2 Commands Reference. IBM Corporation. 2018. p. 282.
  17. Personal conversation with Dick Haight, 12 September 2019.
  18. The /FILES file, A/UX 3.0.1 installation media, Apple Inc. (1993)
  19. "Language BS", 99 Bottles of Beer , 8 August 1996. Retrieved on 9 September 2019.