[20191010]bash行計算器.txt
[20191010]bash行計算器.txt
--//寫一個bash行計算器,為了避免衝突,函式命名為2個=,1個=感覺不是很好(心裡上^_^)。
--//使用bc計算器,裡面函式不能使用圓括號,使用中括號代替。
== ()
{
local in="$(echo "$@" | sed -e 's/\[/(/g' -e 's/\]/)/g')";
echo $in | bc -lq | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//"
}
--//寫入.bashrc指令碼里面就ok了.
--//一些測試:
$ == "scale=4;4/3"
1.3333
--//有分號要加引號才行.
$ == 12*5+11.234
71.234
$ == l[100]/l[10]+1.234
3.234
--//函式使用中括號代替源括號.
$ == s[3.14159]
.00000265358979323534
$ == 2^240
1766847064778384329583297500742918515827483896875618958121606201292619776
--//在bc下執行出現折行情況.
$ echo 2^240 | bc -lq
17668470647783843295832975007429185158274838968756189581216062012926\
19776
$ == "scale=100;a(1)*4"
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170676
--//PI小數點100位.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2659611/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20230428]bash實現xor計算.txt
- [20181229]bash shell的算術運算 .txt
- [20190929]bash使用bc計算的相關問題.txt
- [20201109]bash shell特殊算術方式.txt
- [20191012]使用bash從sql_id計算hash_value.txtSQL
- [20211009]使用bash計算sql語句的sql_id.txtSQL
- [20191011]通過bash計算sql語句的sql_id.txtSQL
- [20211220]sqlplus簡單計算器.txtSQL
- [20181203]bash here $.txt
- [20180930]bash shell &.txt
- [20210318]bash test (( )) [[ ]].txt
- [20210618]記錄bash shell執行的命令.txt
- [20190312]bash IFS例子.txt
- [20231023]生成bbed的執行指令碼(bash shell).txt指令碼
- [20180413]bash 位置引數.txt
- [20180926]bash與分號.txt
- [20221104]bash exec使用技巧.txt
- [20210908]Reverse Shell with Bash.txt
- [20210207]bash history小技巧.txt
- [20190126]從sqlplus執行結果返回bash shell變數.txtSQL變數
- [20181212]bash shell 字串 補零.txt字串
- [20201116]bash shell IO重定向.txt
- [20210913]bash shell $* and $@ 的區別.txt
- №20191010◆手遊1~8◆
- [20190412]bash顯示日期相減.txt
- [20231123]函式與bash shell呼叫.txt函式
- [20201109]here-doc(EOF) in bash.txt
- [20181230]Git Bash啟動緩慢.txtGit
- [20230314]nc reverse bash shell alias.txt
- [20230310]nc reverse bash shell問題.txt
- [20210218]bash echo 建立順序號.txt
- python 計算txt文字詞頻率Python
- [20190821]關於CPU成本計算.txt
- [20190419]bash單雙引號問題.txt
- [20210324]bash shell value too great for base.txt
- 計算器
- [20191127]表 full Hash Value的計算.txt
- [20200217]bash顯示path環境變數.txt變數