home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: dbx Chapter 2
UNIX Commands
Next: Reference: dd
 

dc



dc

 [

file

]

An interactive desk calculator program that performs arbitrary- precision integer arithmetic (input may be taken from a file ). Normally you don't run dc directly, since it's invoked by bc (see bc ). dc provides a variety of one-character commands and operators that perform arithmetic; dc works like a Reverse Polish calculator; therefore, operators and commands follow the numbers they affect. Operators include + - / * % ^ (as in C); some simple commands include:

p

Print current result.

q

Quit dc .

c

Clear all values on the stack.

v

Take square root.

i

Change input base; similar to bc 's ibase .

o

Change output base; similar to bc 's obase .

k

Set scale factor (number of digits after decimal); similar to bc 's scale .

!

Remainder of line is a UNIX command.

Examples

3 2 ^ p	
Evaluate 3 squared, then print result
.
9 
8 * p	
Current value (9) times 8, then print result
.
72 
47 - p	
Subtract 47 from 72, then print result
.
25
v p	
Square root of 25, then print result
.
5
2 o p	
Display current result in base 2
.
101

Note: Spaces are not needed except between numbers.


Previous: Reference: dbx UNIX in a Nutshell: System V Edition Next: Reference: dd
Reference: dbx Book Index Reference: dd

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System