bc 命令
bc命令是一種支持任意精度的交互執(zhí)行的計算器語言。是Linux簡單的計算器,能進(jìn)行進(jìn)制轉(zhuǎn)換與計算。能轉(zhuǎn)換的進(jìn)制包括十六進(jìn)制、十進(jìn)制、八進(jìn)制、二進(jìn)制等。可以使用的運(yùn)算符號包括(+)加法、(-)減法、(*)乘法、(/)除法、(^)指數(shù)、(%)余數(shù)
語法(選項)
-i:強(qiáng)制進(jìn)入交互式模式; -l:定義使用的標(biāo)準(zhǔn)數(shù)學(xué)庫; -w:對POSIX bc的擴(kuò)展給出警告信息; -q:不打印正常的GNU bc環(huán)境信息; -v:顯示指令版本信息; -h:顯示指令的幫助信息。例子
執(zhí)行浮點運(yùn)算和一些高級函數(shù):
[root@study ~]# echo "1.1234*5" | bc 5.6170設(shè)定小數(shù)精確度
[root@study ~]# echo "scale=3;10/3" | bc 3.333參數(shù)scale=3是將bc輸出結(jié)果的小數(shù)位設(shè)置為3位
進(jìn)制轉(zhuǎn)換
[root@study ~]# vim obase.sh1 #!/bin/bash2 3 abc=255 4 echo "obase=2;$abc" | bc # 將十進(jìn)制轉(zhuǎn)換為二進(jìn)制 5 6 def=11110000 7 echo "obase=10;ibase=2;$def" | bc # 將二進(jìn)制轉(zhuǎn)換為十進(jìn)制 [root@study ~]# . obase.sh 11111111 240bc --help
[root@study ~]# bc --help usage: bc [options] [file ...]-h --help print this usage and exit-i --interactive force interactive mode-l --mathlib use the predefined math routines-q --quiet don't print initial banner -s --standard non-standard bc constructs are errors -w --warn warn about non-standard bc constructs -v --version print version information and exit [root@study ~]#轉(zhuǎn)載于:https://www.cnblogs.com/xieshengsen/p/6562363.html
總結(jié)
- 上一篇: libvirtError: 无效参数:c
- 下一篇: [译]震惊!RxJava 5 个不为人知