📜  Linux 中的 dc 命令及示例

📅  最后修改于: 2022-05-13 01:57:05.332000             🧑  作者: Mango

Linux 中的 dc 命令及示例

Linux 中的dc命令用于计算算术表达式。它以后缀表达式的形式计算表达式。输入一个数字会将其推入堆栈,输入一个运算符会计算一个表达式并将结果推回堆栈。它可以计算 +、-、/、*、%、^。可以使用不同的命令来操作堆栈。

句法:

dc [OPTION] [file ...]

下表说明了不同的命令及其解释:

CommandOperation
pPrints the value on the top of the stack and ends the statement with a newline.
nPrints the value on the top of the stack and ends the line with a null statement.
fPrints the entire stack, without any alteration.
PPops the value from the top of the stack.
cClear the stack.
dDuplicates the top value and push it into the main stack.
rReverses the order of top two elements in the stack.
ZPops the value from the stack, calculate the number of digits in it and pushes that number.
XPops the value from the stack, calculate the number of fraction digits in it and pushes that number.
zPushes the stack length into the stack.
iPops the value from the stack and uses it as input radix.
oPops the value from the stack and uses it as output radix.
kPops the values from the stack and uses it to set precision.
IPushes the value of input radix into the stack.
OPushes the value of output radix into the stack
KPushes the precision value into the stack.

示例 1:

示例 2:

注意:在第二个例子中,输出改变是因为我们改变了输出基数。

选项:

  • 表达式:此命令用于评估特定表达式。

  • file :此命令用于评估文件的内容。

  • help :此命令显示帮助信息。

  • version :该命令用于显示版本信息。