我试图在bash中为我的儿子展示毕达哥拉斯定理——这应该很容易。我需要它的功能。然而,定理a2+b2=c2在这里没有意义。不知道我做错了什么。
#!/bin/bash read side_a side_b hypo=$(( (side_a*side_a) + (side_b*side_b) )) echo "side: $side_a side: $side_b hypotenuse: $hypo" $ /tmp/hypo 5 5 side: 5 side: 5 hypotenuse: 50
awk
$ awk '{print "side:",$1,"side:",$2,"hypotenuse:",sqrt($1^2+$2^2)}' 3 4 side: 3 side: 4 hypotenuse: 5
$1 和 $2 如果是输入字段,则其余字段的读取应该很简单。
$1
$2
只需稍加努力,您也可以生成整数解。。。
$ awk 'BEGIN{for(i=1;i<=10;i++) for(j=1;j<i;j++) print 2*i*j, i^2-j^2, i^2+j^2}' 4 3 5 6 8 10 12 5 13 8 15 17 16 12 20 24 7 25 10 24 26 20 21 29 30 16 34 40 9 41 12 35 37 ...