alt-bc.sh

来自「一本完整的描述Unix Shell 编程的工具书的所有范例」· Shell 代码 · 共 56 行

SH
56
字号
#!/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...hyp=             # Declare global variable.hypotenuse ()    # Calculate hypotenuse of a right triangle.{hyp=$(bc -l << EOFscale = 9sqrt ( $1 * $1 + $2 * $2 )EOF)# Unfortunately, can't return floating point values from a Bash function.}hypotenuse 3.68 7.31echo "hypotenuse = $hyp"    # 8.184039344exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?