📄 alt-bc.sh
字号:
#!/bin/bash# Invoking 'bc' using command substitution# in combination with a 'here document'.var1=`bc << EOF18.33 * 19.78EOF`echo $var1 # 362.56# $( ... ) notation also works.v1=23.53v2=17.881v3=83.501v4=171.63var2=$(bc << EOFscale = 4a = ( $v1 + $v2 )b = ( $v3 * $v4 )a * b + 15.35EOF)echo $var2 # 593487.8452var3=$(bc -l << EOFscale = 9s ( 1.7 )EOF)# Returns the sine of 1.7 radians.# The "-l" option calls the 'bc' math library.echo $var3 # .991664810# Now, try it in a function...hypotenuse () # Calculate hypotenuse of a right triangle.{ # c = sqrt( a^2 + b^2 )hyp=$(bc -l << EOFscale = 9sqrt ( $1 * $1 + $2 * $2 )EOF)# Can't directly return floating point values from a Bash function.# But, can echo-and-capture:echo "$hyp"}hyp=$(hypotenuse 3.68 7.31)echo "hypotenuse = $hyp" # 8.184039344exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -