Compiles and interprets modest-sized programs.
bs [ File [ Arguments ] ]
The bs command is a compiler and interpreter for interactive program development and debugging. To simplify program testing, it minimizes formal data declaration and file manipulation, allows line-at-a-time debugging, and provides trace and dump facilities and run-time error messages.
The optional parameter File specifies a file of program statements that you create and that the compiler reads before it reads from standard input. Statements entered from standard input are normally executed immediately (see compile and execute statement syntax). By default, statements read from File are compiled for later execution.
Unless the final operator is assignment to a variable, the result of an immediate expression statement is displayed.
Additional command line Arguments can be passed to the program using the built-in functions arg and narg.
Program lines must conform to one of the following formats:
statement label statement
The interpreter accepts labeled statements only when it is compiling statements. A label is a name immediately followed by a colon. A label and a variable can have the same name. If the last character of a line is a \ (backslash), the statement continues on the following physical line.
A statement consists of either an expression or a keyword followed by zero or more expressions.
Note: To avoid unpredictable results when using a range expression in the international environment, use a character class expression rather than a standard range expression.
break | Exits the innermost for or while loop. |
clear | Clears the symbol table and removes compiled statements from memory. A clear is always executed immediately. |
compile [Expression] | Causes succeeding statements to be compiled (overrides the immediate execution default). The optional Expression is evaluated and used as a file name for further input. In this latter case, the symbol table and memory are cleared first. compile is always executed immediately. |
continue | Transfers control to the loop-continuation test of the current for or while loop. |
dump [Name] | Displays the name and current value of every global variable or, optionally, of the Named variable. After an error or interrupt, dump displays the number of the last statement and (possibly) the user-function trace. |
exit [Expression] | Returns to the system level. The Expression is returned as process status. |
execute | Changes to immediate execution mode (pressing the INTERRUPT key has the same effect). This statement does not cause stored statements to execute (see run). |
for | Performs repeatedly, under the control of a named variable, a statement or a group of statements using one of the following syntaxes:
for name=Expression Expression statement next for name=Expression Expression statement . . . next for Expression, Expression, Expression statement next for Expression, Expression, Expression statement . . . next The first format specifes a single statement where the variable takes on the value of the first expression and then is increased by one on each loop until it exceeds the value of the second expression. You can use the second format to do the same thing , but you can specify a group of statements. The third format requires an initialization expression followed by a test expression (such as true to continue) and a loop-continuation action expression. You can use the fourth format to do the same thing, but you can specify a group of statements. Use commas to separate the expressions in the third and fourth formats. |
fun | Defines a user-written function using the following syntax:
fun f ([a, . . . ]) [v, . . . ] statement . . . nuf f specifies the function name, a specifies any parameters, and v identifies any local variables for the user-written function. You can specify up to 10 parameters and local variables; however, they cannot be arrays or associated with I/O functions. You cannot nest function definitions. |
freturn | Signals the failure of a user-written function. Without interrogation, freturn returns zero. (See the unary interrogation operator (?).) With interrogation, freturn transfers to the interrogated expression, possibly bypassing intermediate function returns. |
goto Name | Passes control to the compiled statement with the matching label of Name. |
ibase n | Sets the input base to n. The only supported values for n are 8, 10 (the default), and 16. Hexadecimal values 10-15 are entered as alphabetic characters a-f. A leading digit is required when a hexadecimal number begins with an alphabetic character (for example, f0a must be entered as 0f0a). ibase is always executed immediately. |
if | Performs a statement in one of the following syntaxes:
if Expression statement [else statement . . . ] fi if Expression statement . . . [else statement . . . ] fi The first format specifies a single statement and the second format specifies a group of statements to continue using if the expression evaluates to nonzero. The strings 0 and "" (null) evaluate as zero. In the second format, an optional else allows a group of statements to be performed when the first group is not. The only statement permitted on the same line with an else is an if. You can put fis only on the same line as another fi. You can combine else and if into elif. You can close an if . . . elif . . . [else . . . ] sequence with a single fi. |
include Expression | Evaluates an Expression to the name of a file containing program statements. Such statements become part of the program being compiled. The include statements are always executed immediately. Do not nest include statements. |
obase n | Sets the output base to n. The only supported values for n are 8, 10 (the default), and 16. Hexadecimal values 10 through15 are entered as alphabetic characters a-f. A leading digit is required when a hexadecimal number begins with an alphabetic character (that is, f0a must be entered as 0f0a). Like ibase, obase is always executed immediately. |
onintr | Provides program control of interrupts using one of the following syntaxes:
onintr Label onintr In the first format, control passes to the Label given, just as if a goto had been performed when onintr was executed. The effect of the onintr statement is cleared after each interrupt. In the second format, pressing INTERRUPT ends the bs program. |
return [Expression] | Evaluates the Expression and passes the result back as the value of a function call. If you do not provide an expression, the function returns zero. |
run | Passes control to the first compiled statement. The random number generator is reset. If a file contains a run statement, it should be the last statement; run is always executed immediately. |
stop | Stops execution of compiled statements and returns to immediate mode. |
trace [Expression] | Controls function tracing. If you do not provide an Expression or if it evaluates to zero, tracing is turned off. Otherwise, a record of user-function calls/returns will be written. Each return decreases by one the trace expression value. |
while | Performs repeatedly, under the control of a named variable, a statement or a group of statements using one of the following syntaxes:
while Expression statement next while Expression statement . . . next The while statement is similar to the for statement except that only the conditional expression for loop continuation is given. |
!cmd | Runs a command and then returns control to the bs program. |
# Comment | Inserts a comment line. |
Name | Specifies a variable or, when followed immediately by a colon, a label. Names are composed of a letter (uppercase or lowercase) optionally followed by letters and digits. Only the first six characters of a name are significant. Except for names declared locally in fun statements, all names are global. Names can take on numeric (double float) values or string values or be associated with input/output (see the built-in function open). |
Name([Expression[, Expression] . . . ]) | |
Calls function Name and passes to it the parameters in parentheses. Except for built-in functions, Name must be defined in a fun statement. Function parameters are passed by value. | |
Name[Expression[, Expression] . . . ] | |
References either arrays or tables (see built-in function table). For arrays, each expression is truncated to an integer and used as a specifier for the name. The resulting array reference is syntactically identical to a name; a [1,2] is the same as a [1] [2]. The truncated expressions must be values between 0 and 32,767. | |
Number | Represents a constant numerical value. This number can be expressed in integer, decimal, or scientific notation (it can contain digits, an optional decimal point, and an optional e followed by a possibly signed exponent). |
String | Represents a character string delimited by " " (double quotation marks). Within the string, you can use the \ (backslash) as an escape character that allows the double quotation mark (\"), new-line character (\n), carriage return(\r), backspace (\b), and tab (\t) characters to appear in a string. When not immediately followed by these special characters, \ stands for itself. |
(Expression) | Alters the normal order of evaluation. |
(Expression, Expression[, Expression] . . . ) [Expression] | |
Specifies to use the bracketed expression outside the parentheses as a subscript to the list of expressions within the parentheses. List elements are numbered from the left, starting at zero. The following expression has the value of True if the comparison is true:
(False, True) [a == b] | |
Expression Operator Expression | Converts the operands to numeric form before the operator is applied unless the operator is an assignment, concatenation, or relational operator. |
? Expression | Tests for the success of Expression rather than its value. This interrogation operator is useful for testing:
An interrogation trap (end of file, for example), causes an immediate transfer to the most recent interrogation, possibly skipping assignment statements or intervening function levels. |
- Expression | Negates Expression. |
++ Name | Increases by one the value of the variable (or array reference). |
-- Name | Decreases by one the value of the variable. |
! Expression | Specifies the logical negation of Expression. |
Note: Unary operators treat a null string as a zero.
= | Specifies the assignment operator. The left operand must be a name or array element. It acquires the value of the right operand. Assignment binds right to left; all other operators bind left to right. |
_ | Specifies the concatenation operator. (It is the underline character). |
& | | Specifies logical AND, logical OR.
is 1 (true) only if both of its parameters are non-zero (true); it is 0 (false) if one or both of its parameters are 0 (false). is 1 (true) if one or both of its expressions are non-zero (true); it is 0 (false) only if both of its expressions are 0 (false). Both operators treat a null string as a zero. |
< <= > >= == != | Specifies the relational operators:
The relational operators return 1 if the specified relation is True; otherwise they return 0 (false). Relational operators at the same level extend as follows: a>b>c is the same as a>b& b>c. A string comparison is made if both operands are strings. The comparison is based on the collating sequence specified in the environment variable LC_COLLATE. The National Language Support Overview contains more information on this environment variable. |
+ - | Specifies addition and subtraction. |
* / % | Specifies multiplication, division, and remainder. |
^ | Specifies exponentiation. |
Note: Binary operators treat a null string as a zero.
To execute the bs command and direct the result to a file called output, enter:
bs < input.n > output
bs input.n > output
The ksh command.
The access subroutine, printf subroutine.
The National Language Support Overview for Programming in AIX General Programming Concepts: Writing and Debugging Programs.