📄 hypotenuse.sh
字号:
#!/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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -