hypotenuse.sh

来自「Shall高级编程」· Shell 代码 · 共 29 行

SH
29
字号
#!/bin/bash# hypotenuse.sh: Returns the "hypotenuse" of a right triangle.#                (square root of sum of squares of the "legs")ARGS=2                # Script needs sides of triangle passed.E_BADARGS=65          # Wrong number of arguments.if [ $# -ne "$ARGS" ] # Test number of arguments to script.then  echo "Usage: `basename $0` side_1 side_2"  exit $E_BADARGSfiAWKSCRIPT=' { printf( "%3.7f\n", sqrt($1*$1 + $2*$2) ) } '#             command(s) / parameters passed to awk# Now, pipe the parameters to awk.    echo -n "Hypotenuse of $1 and $2 = "    echo $1 $2 | awk "$AWKSCRIPT"#   ^^^^^^^^^^^^# An echo-and-pipe is an easy way of passing shell parameters to awk.exit 0# Exercise: Rewrite this script using 'bc' rather than awk.#           Which method is more intuitive?

⌨️ 快捷键说明

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