bc 命令
bc命令是一種支持任意精度的交互執行的計算器語言。是Linux簡單的計算器,能進行進制轉換與計算。能轉換的進制包括十六進制、十進制、八進制、二進制等。可以使用的運算符號包括(+)加法、(-)減法、(*)乘法、(/)除法、(^)指數、(%)余數
語法(選項)
-i:強制進入交互式模式; -l:定義使用的標準數學庫; -w:對POSIX bc的擴展給出警告信息; -q:不打印正常的GNU bc環境信息; -v:顯示指令版本信息; -h:顯示指令的幫助信息。例子
執行浮點運算和一些高級函數:
[root@study ~]# echo "1.1234*5" | bc 5.6170設定小數精確度
[root@study ~]# echo "scale=3;10/3" | bc 3.333參數scale=3是將bc輸出結果的小數位設置為3位
進制轉換
[root@study ~]# vim obase.sh1 #!/bin/bash2 3 abc=255 4 echo "obase=2;$abc" | bc # 將十進制轉換為二進制 5 6 def=11110000 7 echo "obase=10;ibase=2;$def" | bc # 將二進制轉換為十進制 [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 ~]#轉載于:https://www.cnblogs.com/xieshengsen/p/6562363.html
總結
- 上一篇: libvirtError: 无效参数:c
- 下一篇: Zeppelin-源码编译