utility bc
To implement an arbitrary precision calculator, use the utility bc command in
EXEC mode or administration EXEC
mode.
utility bc [file input-file]
Syntax Description
file input-file |
(Optional) Specifies the text file containing commands and function definitions to be interpreted by the bc utility. After all files have been read, the bc utility reads input from the standard input (keyboard). If no files are specified, then only the standard input (keyboard) is used. The syntax of the input-file argument is as follows: device :[/ directory-path]/ filename Possible values of the device: argument are:
Use the online help (? ) function to display the available devices and network protocols. |
Command Default
If an input file is not specified, the standard input (keyboard) is used.
Command Modes
EXEC
Administration EXEC
Command History
Release |
Modification |
---|---|
Release 3.7.2 |
This command was introduced. |
Usage Guidelines
To use this command, you must be in a user group associated with a task group that includes appropriate task IDs. If the user group assignment is preventing you from using a command, contact your AAA administrator for assistance.
Use the utility bc command to use the interactive, programmable calculator that supports a complete set of control structures, including functions. The utility first processes any specified files, and then reads input from the keyboard (standard input).
Input files (and standard input) are ASCII text files containing sequences of bc statements to be executed.
Note |
The bc utility uses the bc programming language, an arbitrary precision calculator language with syntax similar to the C programming language. The bc utility does not support character or string manipulation. |
The bc utility supports:
- 26 functions
- 26 simple variables
- 26 array variables (up to 2048 elements per array).
The bc utility supports the following common programming language constructs:
- “if”, “while”, and “for” statements
- User-defined functions with parameters
- Local variables
Information About Supported Network Protocols
In the syntax for the ftp: , rcp: , and tftp: network protocols, the location is either an IP address or a hostname. The filename is specified relative to the directory used for file transfers.
When no device is specified, the current directory is used. To view the current directory, enter the pwd command.
Prefix |
Name |
Description |
---|---|---|
tftp: |
Trivial File Transfer Protocol |
TFTP is a simplified version of FTP that allows files to be transferred from one computer to another over a network, usually without the use of client authentication (for example, username and password). |
ftp: |
File Transfer Protocol |
FTP is an application protocol, part of the TCP/IP protocol stack, and is used for transferring files between network nodes. FTP requires a username and password. |
rcp: |
remote copy protocol |
Rcp is a protocol that allows users to copy files to and from a file system residing on a remote host or server on the network. Rcp uses TCP to ensure the reliable delivery of data. Rcp downloads require a username. |
Task ID
Task ID |
Operations |
---|---|
universal |
execute |
Examples
In the following example, the utility bc command is used to execute the bc statements contained in the ASCII text file exp.txt:
RP/0/RSP0/CPU0:router# utility bc file disk0:/usr/exp.txt
50
15
25
3
17