N methods for shell mathematical calculation

let usage method
[email protected]:/tmp# n1=5
[email protected]:/tmp# n2=10< br />[email protected]:/tmp# let result=n1+n2
[email protected]:/tmp# echo $result
15
[email protected]:/tmp# let n1++
[email protected]:/tmp# echo $n1
6
[email protected]:/tmp# let n1--
[email protected]:/tmp# echo $n1
5
[email protected]:/tmp# let n1+=6
[email protected]:/tmp# echo $n1
11
$[] Calculate
[email protected]:/tmp/pratice# n1=5
[email protected]:/tmp/pratice# n2=10
[email protected]:/tmp/pratice# result2=$[ n1 + n2 ]
[email protected]:/tmp/pratice# echo $result2
15
$(()) Calculation
[emailprotected]:/tmp# echo $(( 1+2 ))
3
[emailprotected]:/tmp # echo $((1-9))
-8
expr to calculate
[emailprotected]:/tmp# result =`expr 10-3` # There is no space before and after the operator, which makes it impossible to calculate
[emailprotected]:/tmp# echo $result
10-3
[emailprotected] :/tmp# result=`expr 10-3`
[email protected]:/tmp# echo $result
7
[email protected]:/tmp# result=$(expr $ n1 + 4)
[email protected]:/tmp# echo $result
15
[email protected]:/tmp# echo $n1
11
bc to calculate
[email protected]:/tmp# echo "4*12*0.3" | bc
14.4
[email protected] :/tmp# result2=`echo "4*12*0.3" | bc`
[emailprotected]:/tmp# echo $result2
14.4

Control precision by scale

[email protected]:/tmp# echo "scale=3;3.1415926*7/2.1234987" | bc
10.356
[email protected]:/tmp# echo "scale= 30;3.1415926*7/2.1234987" | bc
10.356092141709340344780997511324

Decimal and binary conversion

[emailprotected]:/tmp# n=100
[email protected]:/tmp# echo "obase=2;$n" | bc
1100100
[email protected]:/tmp# n2=1100100
[email protected]: /tmp# echo "obase=10;ibase=2;$n2" | bc
100

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5501 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.